Hello,
A thing I want to do when importing C code in moose , is to see if a function is Private or Public. After reading some documentations about C, a private function ( A function that can't be used outside the module in which it's defined) is a function declared with 'Static'. Am I wrong ?
If this is ok, the first thing is: => FAMIXFunction > isPublic just check if the function is called outside the module. This does not really correspond to the description above. the secong thing is: => How can I see if a function is declared with 'static' ? For the moment I can have this information in the signatiure of the function. But to retrieve that, I have to parse the string.
_______________________________________________ Moose-dev mailing list [hidden email] https://www.iam.unibe.ch/mailman/listinfo/moose-dev |
Hi Cyrille,
This is not quite exact. A static function is a function that is visible only in the file that defines it. It is true that it could be assimilated as a private function. But the privacy is also obtained by not having the function signature in the .h file. Contrary to Java, there is no such a keyword in C that says if a function is private a or public, but there is a number of technical conventions. Alexandre On 22 Jan 2010, at 07:18, Cyrille Delaunay wrote: > Hello, > > A thing I want to do when importing C code in moose , is to see if a > function is Private or Public. > After reading some documentations about C, a private function ( A > function that can't be used outside the module in which it's > defined) is a function declared with 'Static'. Am I wrong ? > > If this is ok, the first thing is: > => FAMIXFunction > isPublic just check if the function is called > outside the module. This does not really correspond to the > description above. > > the secong thing is: > => How can I see if a function is declared with 'static' ? > For the moment I can have this information in the signatiure of > the function. But to retrieve that, I have to parse the string. > > _______________________________________________ > Moose-dev mailing list > [hidden email] > https://www.iam.unibe.ch/mailman/listinfo/moose-dev -- _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: Alexandre Bergel http://www.bergel.eu ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;. _______________________________________________ Moose-dev mailing list [hidden email] https://www.iam.unibe.ch/mailman/listinfo/moose-dev |
If I have a function 'int f1(void)' defined in 'file1.c'.
If I declared at the begining of another file 'file2.c' : 'extern int f1(void);' , and use it later in this file (without declaring it in a '.h' file) .
Will it work ?
2010/1/22 Alexandre Bergel <[hidden email]> Hi Cyrille, _______________________________________________ Moose-dev mailing list [hidden email] https://www.iam.unibe.ch/mailman/listinfo/moose-dev |
> If I have a function 'int f1(void)' defined in 'file1.c'.
> If I declared at the begining of another file 'file2.c' : 'extern > int f1(void);' , and use it later in this file (without declaring it > in a '.h' file) . > Will it work ? He he, 'extern' is a way to say that the function is defined somewhere else. It is therefore public. http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/version/Doc/Manual/external.html#ExternDecls Alexandre NB: I am now away until this evening. without internet. > > 2010/1/22 Alexandre Bergel <[hidden email]> > Hi Cyrille, > > This is not quite exact. A static function is a function that is > visible only in the file that defines it. It is true that it could > be assimilated as a private function. But the privacy is also > obtained by not having the function signature in the .h file. > Contrary to Java, there is no such a keyword in C that says if a > function is private a or public, but there is a number of technical > conventions. > > Alexandre > > > > On 22 Jan 2010, at 07:18, Cyrille Delaunay wrote: > > Hello, > > A thing I want to do when importing C code in moose , is to see if a > function is Private or Public. > After reading some documentations about C, a private function ( A > function that can't be used outside the module in which it's > defined) is a function declared with 'Static'. Am I wrong ? > > If this is ok, the first thing is: > => FAMIXFunction > isPublic just check if the function is called > outside the module. This does not really correspond to the > description above. > > the secong thing is: > => How can I see if a function is declared with 'static' ? > For the moment I can have this information in the signatiure of > the function. But to retrieve that, I have to parse the string. > > _______________________________________________ > Moose-dev mailing list > [hidden email] > https://www.iam.unibe.ch/mailman/listinfo/moose-dev > > -- > _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: > Alexandre Bergel http://www.bergel.eu > ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;. > > > > > > _______________________________________________ > Moose-dev mailing list > [hidden email] > https://www.iam.unibe.ch/mailman/listinfo/moose-dev > > _______________________________________________ > Moose-dev mailing list > [hidden email] > https://www.iam.unibe.ch/mailman/listinfo/moose-dev -- _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: Alexandre Bergel http://www.bergel.eu ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;. _______________________________________________ Moose-dev mailing list [hidden email] https://www.iam.unibe.ch/mailman/listinfo/moose-dev |
Yep, this is a topic to discuss, because the way to interpret function visibility is still unclear to me: So we have: - static functions, which really are private (visibility reduced to file) - functions defined in c file but not in header file - however, you could still find an extern declaration to this function in another file. - functions defined in c file and in header file - which is the convention for good C projects as Alex noted Anyway, by default a function is globally visible, but you have to include its declaration (through an include header or a declaration) somewhere if you want to use it in your file and it has not been defined before. Also, the convention when one finds an 'extern declaration' is to consider that the function is not defined in the corresponding c file, but in another c file. So I would suggest the following conventions: - static functions: private - functions defined but not declared (even through an extern): 'local' - functions defined and declared in corresponding header: public - functions defined and declared with extern somewhere else: global? On 22 janv. 2010, at 12:07, Alexandre Bergel wrote: >> If I have a function 'int f1(void)' defined in 'file1.c'. >> If I declared at the begining of another file 'file2.c' : 'extern int f1(void);' , and use it later in this file (without declaring it in a '.h' file) . >> Will it work ? > > He he, 'extern' is a way to say that the function is defined somewhere else. It is therefore public. > http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/version/Doc/Manual/external.html#ExternDecls > > Alexandre > > NB: I am now away until this evening. without internet. > >> >> 2010/1/22 Alexandre Bergel <[hidden email]> >> Hi Cyrille, >> >> This is not quite exact. A static function is a function that is visible only in the file that defines it. It is true that it could be assimilated as a private function. But the privacy is also obtained by not having the function signature in the .h file. Contrary to Java, there is no such a keyword in C that says if a function is private a or public, but there is a number of technical conventions. >> >> Alexandre >> >> >> >> On 22 Jan 2010, at 07:18, Cyrille Delaunay wrote: >> >> Hello, >> >> A thing I want to do when importing C code in moose , is to see if a function is Private or Public. >> After reading some documentations about C, a private function ( A function that can't be used outside the module in which it's defined) is a function declared with 'Static'. Am I wrong ? >> >> If this is ok, the first thing is: >> => FAMIXFunction > isPublic just check if the function is called outside the module. This does not really correspond to the description above. >> >> the secong thing is: >> => How can I see if a function is declared with 'static' ? >> For the moment I can have this information in the signatiure of the function. But to retrieve that, I have to parse the string. >> >> _______________________________________________ >> Moose-dev mailing list >> [hidden email] >> https://www.iam.unibe.ch/mailman/listinfo/moose-dev >> >> -- >> _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: >> Alexandre Bergel http://www.bergel.eu >> ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;. >> >> >> >> >> >> _______________________________________________ >> Moose-dev mailing list >> [hidden email] >> https://www.iam.unibe.ch/mailman/listinfo/moose-dev >> >> _______________________________________________ >> Moose-dev mailing list >> [hidden email] >> https://www.iam.unibe.ch/mailman/listinfo/moose-dev > > -- > _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: > Alexandre Bergel http://www.bergel.eu > ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;. > > > > > > _______________________________________________ > Moose-dev mailing list > [hidden email] > https://www.iam.unibe.ch/mailman/listinfo/moose-dev -- Simon _______________________________________________ Moose-dev mailing list [hidden email] https://www.iam.unibe.ch/mailman/listinfo/moose-dev |
On Jan 22, 2010, at 1:12 PM, Simon Denier wrote: > > Yep, this is a topic to discuss, because the way to interpret function visibility is still unclear to me: > > So we have: > > - static functions, which really are private (visibility reduced to file) > - functions defined in c file but not in header file - however, you could still find an extern declaration to this function in another file. > - functions defined in c file and in header file - which is the convention for good C projects as Alex noted > > Anyway, by default a function is globally visible, but you have to include its declaration (through an include header or a declaration) somewhere if you want to use it in your file and it has not been defined before. yes > Also, the convention when one finds an 'extern declaration' is to consider that the function is not defined in the corresponding c file, but in another c file. > > So I would suggest the following conventions: > - static functions: private > - functions defined but not declared (even through an extern): 'local' do they are really local? > - functions defined and declared in corresponding header: public > - functions defined and declared with extern somewhere else: global? > > > > On 22 janv. 2010, at 12:07, Alexandre Bergel wrote: > >>> If I have a function 'int f1(void)' defined in 'file1.c'. >>> If I declared at the begining of another file 'file2.c' : 'extern int f1(void);' , and use it later in this file (without declaring it in a '.h' file) . >>> Will it work ? >> >> He he, 'extern' is a way to say that the function is defined somewhere else. It is therefore public. >> http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/version/Doc/Manual/external.html#ExternDecls >> >> Alexandre >> >> NB: I am now away until this evening. without internet. >> >>> >>> 2010/1/22 Alexandre Bergel <[hidden email]> >>> Hi Cyrille, >>> >>> This is not quite exact. A static function is a function that is visible only in the file that defines it. It is true that it could be assimilated as a private function. But the privacy is also obtained by not having the function signature in the .h file. Contrary to Java, there is no such a keyword in C that says if a function is private a or public, but there is a number of technical conventions. >>> >>> Alexandre >>> >>> >>> >>> On 22 Jan 2010, at 07:18, Cyrille Delaunay wrote: >>> >>> Hello, >>> >>> A thing I want to do when importing C code in moose , is to see if a function is Private or Public. >>> After reading some documentations about C, a private function ( A function that can't be used outside the module in which it's defined) is a function declared with 'Static'. Am I wrong ? >>> >>> If this is ok, the first thing is: >>> => FAMIXFunction > isPublic just check if the function is called outside the module. This does not really correspond to the description above. >>> >>> the secong thing is: >>> => How can I see if a function is declared with 'static' ? >>> For the moment I can have this information in the signatiure of the function. But to retrieve that, I have to parse the string. >>> >>> _______________________________________________ >>> Moose-dev mailing list >>> [hidden email] >>> https://www.iam.unibe.ch/mailman/listinfo/moose-dev >>> >>> -- >>> _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: >>> Alexandre Bergel http://www.bergel.eu >>> ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;. >>> >>> >>> >>> >>> >>> _______________________________________________ >>> Moose-dev mailing list >>> [hidden email] >>> https://www.iam.unibe.ch/mailman/listinfo/moose-dev >>> >>> _______________________________________________ >>> Moose-dev mailing list >>> [hidden email] >>> https://www.iam.unibe.ch/mailman/listinfo/moose-dev >> >> -- >> _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: >> Alexandre Bergel http://www.bergel.eu >> ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;. >> >> >> >> >> >> _______________________________________________ >> Moose-dev mailing list >> [hidden email] >> https://www.iam.unibe.ch/mailman/listinfo/moose-dev > > -- > Simon > > > > > _______________________________________________ > Moose-dev mailing list > [hidden email] > https://www.iam.unibe.ch/mailman/listinfo/moose-dev _______________________________________________ Moose-dev mailing list [hidden email] https://www.iam.unibe.ch/mailman/listinfo/moose-dev |
In reply to this post by Simon Denier-3
> So I would suggest the following conventions:
> - static functions: private > - functions defined but not declared (even through an extern): 'local' > - functions defined and declared in corresponding header: public > - functions defined and declared with extern somewhere else: global? Do we need more than just public/private? Alexandre > > > > On 22 janv. 2010, at 12:07, Alexandre Bergel wrote: > >>> If I have a function 'int f1(void)' defined in 'file1.c'. >>> If I declared at the begining of another file 'file2.c' : 'extern >>> int f1(void);' , and use it later in this file (without declaring >>> it in a '.h' file) . >>> Will it work ? >> >> He he, 'extern' is a way to say that the function is defined >> somewhere else. It is therefore public. >> http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/version/Doc/Manual/external.html#ExternDecls >> >> Alexandre >> >> NB: I am now away until this evening. without internet. >> >>> >>> 2010/1/22 Alexandre Bergel <[hidden email]> >>> Hi Cyrille, >>> >>> This is not quite exact. A static function is a function that is >>> visible only in the file that defines it. It is true that it could >>> be assimilated as a private function. But the privacy is also >>> obtained by not having the function signature in the .h file. >>> Contrary to Java, there is no such a keyword in C that says if a >>> function is private a or public, but there is a number of >>> technical conventions. >>> >>> Alexandre >>> >>> >>> >>> On 22 Jan 2010, at 07:18, Cyrille Delaunay wrote: >>> >>> Hello, >>> >>> A thing I want to do when importing C code in moose , is to see if >>> a function is Private or Public. >>> After reading some documentations about C, a private function ( A >>> function that can't be used outside the module in which it's >>> defined) is a function declared with 'Static'. Am I wrong ? >>> >>> If this is ok, the first thing is: >>> => FAMIXFunction > isPublic just check if the function is called >>> outside the module. This does not really correspond to the >>> description above. >>> >>> the secong thing is: >>> => How can I see if a function is declared with 'static' ? >>> For the moment I can have this information in the signatiure of >>> the function. But to retrieve that, I have to parse the string. >>> >>> _______________________________________________ >>> Moose-dev mailing list >>> [hidden email] >>> https://www.iam.unibe.ch/mailman/listinfo/moose-dev >>> >>> -- >>> _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: >>> Alexandre Bergel http://www.bergel.eu >>> ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;. >>> >>> >>> >>> >>> >>> _______________________________________________ >>> Moose-dev mailing list >>> [hidden email] >>> https://www.iam.unibe.ch/mailman/listinfo/moose-dev >>> >>> _______________________________________________ >>> Moose-dev mailing list >>> [hidden email] >>> https://www.iam.unibe.ch/mailman/listinfo/moose-dev >> >> -- >> _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: >> Alexandre Bergel http://www.bergel.eu >> ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;. >> >> >> >> >> >> _______________________________________________ >> Moose-dev mailing list >> [hidden email] >> https://www.iam.unibe.ch/mailman/listinfo/moose-dev > > -- > Simon > > > > > _______________________________________________ > Moose-dev mailing list > [hidden email] > https://www.iam.unibe.ch/mailman/listinfo/moose-dev -- _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: Alexandre Bergel http://www.bergel.eu ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;. _______________________________________________ Moose-dev mailing list [hidden email] https://www.iam.unibe.ch/mailman/listinfo/moose-dev |
Free forum by Nabble | Edit this page |