Re: compile problem on older program
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Sun, Oct 29, 2017 at 11:53:22AM +0100, Thomas Schmitt wrote: > Hi, > > to...@tuxteam.de wrote: > > https://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html > > But my example code has no nested functions. > The two functions are disjoint. The main() function only contains > a type declaration by function prototype, not the function body. > > I can change the code to plain K&R C and gcc still fails: > > static int bla(x) > int x; > { >return (x != 1); > } > int main() > { >static int bla(); >return(bla(0)); > } Right. That's just the declaration... > I found a quote in > > https://stackoverflow.com/questions/22904848/what-is-c-local-function-declaration-mechanism > "The C standard contains the following. n1570/S6.7.1/7: >The declaration of an identifier for a function that has block scope >shall have no explicit storage-class specifier other than extern." > > > I have N1548, which bears the same statement in 6.7.1 as subparagraph 6. > This paragraph refers to "typedef", "extern", "static", "_Thread_local", > "auto", and "register". > A declaration within a function body has block scope, indeed. > (6.2.1 subparagraph 4.) > > So gcc is right when it refuses on "static". The obviousily once existing > tolerance was inappropriate. > I still wonder whether the forbidden storage classes would cause semantic > problems, or whether they shall stay reserved for future use. Yep. Thanks for the clarification (or should it be declarification? ;-) > Have a nice day :) Same :) - -- t -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.12 (GNU/Linux) iEYEARECAAYFAln1w/oACgkQBcgs9XrR2kYuGwCffsamovEFf2JCN2Nh1wSKAfta nVYAnRBfCxVCkTzRNYcGSrTKoAlINSeT =2dKo -END PGP SIGNATURE-
Re: compile problem on older program
Hi, to...@tuxteam.de wrote: > https://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html But my example code has no nested functions. The two functions are disjoint. The main() function only contains a type declaration by function prototype, not the function body. I can change the code to plain K&R C and gcc still fails: static int bla(x) int x; { return (x != 1); } int main() { static int bla(); return(bla(0)); } I found a quote in https://stackoverflow.com/questions/22904848/what-is-c-local-function-declaration-mechanism "The C standard contains the following. n1570/S6.7.1/7: The declaration of an identifier for a function that has block scope shall have no explicit storage-class specifier other than extern." I have N1548, which bears the same statement in 6.7.1 as subparagraph 6. This paragraph refers to "typedef", "extern", "static", "_Thread_local", "auto", and "register". A declaration within a function body has block scope, indeed. (6.2.1 subparagraph 4.) So gcc is right when it refuses on "static". The obviousily once existing tolerance was inappropriate. I still wonder whether the forbidden storage classes would cause semantic problems, or whether they shall stay reserved for future use. Have a nice day :) Thomas
Re: compile problem on older program
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Sat, Oct 28, 2017 at 11:35:59PM +0200, Thomas Schmitt wrote: > Hi, > > it seems that gcc just hates a static function declaration inside a function. > > This code (without any include) > > static int bla(int x) > { >return (x != 1); > } > int main() > { >static int bla(int x); >return(bla(0)); > } > > yields > > t.c: In function ‘main’: > t.c:19:13: error: invalid storage class for function ‘bla’ > static int bla(int x); >^ > > The compile time error vanishes if i move the declaration out of the function, > or if i remove the "static", or if i remove the declaration completely > (as it is surplus in both programs, mine and Fred's). > > I wonder what gives "static int bla(int x);" such a different meaning inside > and outside a function. To my naive but long tested understanding, both > should differ only by their scope. Nested function definitions are a gcc-ism (please don't take this as a pejorative term: personally I do like gcc-isms, but one should know when one's making use of them). Here's more about it. And yes, static or extern don't work with them. But auto does. And g++ doesn't like them (I guess there's a reason): https://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html Cheers - -- t -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.12 (GNU/Linux) iEUEARECAAYFAln1nYAACgkQBcgs9XrR2kYC3gCWJ3TRCDRRDzgT4HxqNYLp28w2 awCeO7tWrqxn3yLKF48daNLizuWa+NU= =o1BZ -END PGP SIGNATURE-
Re: compile problem on older program
On 10/28/2017 02:30 PM, Roberto C. Sánchez wrote: On Sat, Oct 28, 2017 at 01:55:54PM -0700, Fred wrote: Hi, The source is at https://www.pastebin.com/X4a4p9U2 There are many similar lines with static keyword which the compiler didn't complain about. Except that every other line with the static keyword in that file is a proper function prototype declaration (i.e., outside of function scope) or is a function definition. I think that you can safely remove line 821 since that function (isRectangle) is not used at all inside of GBX_PrintPolygon. The only occurrence of isRectangle is in the condition clause of an if statement that the compiler never sees (because it is excluded by the preprocessor). The stackoverflow.com link suggests there is an unmatched bracket but I wasn't able to find one. I don't think you have any unmatched braces in the file. If removing line 821 doesn't fix it, please post the complete source tarball so that we can dig deeper. Regards, -Roberto Hi, Removing line 821 did appear to allow the whole program to compile. A preliminary test has problems with the scroll bars but there is a resource file that may allow that to be fixed. Thanks for the help!! Best regards, Fred
Re: compile problem on older program
Hi, it seems that gcc just hates a static function declaration inside a function. This code (without any include) static int bla(int x) { return (x != 1); } int main() { static int bla(int x); return(bla(0)); } yields t.c: In function ‘main’: t.c:19:13: error: invalid storage class for function ‘bla’ static int bla(int x); ^ The compile time error vanishes if i move the declaration out of the function, or if i remove the "static", or if i remove the declaration completely (as it is surplus in both programs, mine and Fred's). I wonder what gives "static int bla(int x);" such a different meaning inside and outside a function. To my naive but long tested understanding, both should differ only by their scope. Have a nice day :) Thomas
Re: compile problem on older program
On Sat, Oct 28, 2017 at 01:55:54PM -0700, Fred wrote: > Hi, > The source is at https://www.pastebin.com/X4a4p9U2 > > There are many similar lines with static keyword which the compiler didn't > complain about. > Except that every other line with the static keyword in that file is a proper function prototype declaration (i.e., outside of function scope) or is a function definition. I think that you can safely remove line 821 since that function (isRectangle) is not used at all inside of GBX_PrintPolygon. The only occurrence of isRectangle is in the condition clause of an if statement that the compiler never sees (because it is excluded by the preprocessor). > The stackoverflow.com link suggests there is an unmatched bracket but I > wasn't able to find one. > I don't think you have any unmatched braces in the file. If removing line 821 doesn't fix it, please post the complete source tarball so that we can dig deeper. Regards, -Roberto -- Roberto C. Sánchez
Re: compile problem on older program
On 10/28/2017 09:50 AM, Roberto C. Sánchez wrote: On Sat, Oct 28, 2017 at 09:29:16AM -0700, Fred wrote: Hello, I need to compile an older program and have a compile error. How can I resolve this? Unfortunately I am not a C programmer although I do assembler programming. Here is the output of make: making all in ./src... make[1]: Entering directory '/opt/pcb-1.6.3p/src' gcc -m32 -g -O2 -fno-strict-aliasing -Dlinux -D__i386__ -D_POSIX_C_SOURCE=199309L -D_POSIX_SOURCE -D_XOPEN_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DFUNCPROTO=15 -DNARROWPROTO -DRELEASE=\"1.6.3\" -DPCBLIBDIR=\"/home/cad/lib/pcb\" -DBTNMOD=\"Mod1\" -DFONTFILENAME=\"default_font\" -DLIBRARYFILENAME=\"pcblib\" -DGNUM4=\"/usr/bin/m4\" -DHAS_ATEXIT -DHAS_REGEX -c -o dev_rs274x.o dev_rs274x.c dev_rs274x.c: In function ‘GBX_PrintPolygon’: dev_rs274x.c:821:13: error: invalid storage class for function ‘isRectangle’ static int isRectangle(PolygonTypePtr Ptr); ^ : recipe for target 'dev_rs274x.o' failed make[1]: *** [dev_rs274x.o] Error 1 make[1]: Leaving directory '/opt/pcb-1.6.3p/src' Makefile:1071: recipe for target 'all' failed make: *** [all] Error 2 The error is pointing to a function declaration. The source: This source is for the function definition/implementation. We don't even know if this is in the same source file as the line that caused the error (which may or may not be relevant). /* -- * Checks a four-point polygon to see if it's a rectangle. * Tick off pairs of X & Y coords; if we get four matches, * we have a rectangle. */ static int isRectangle(PolygonTypePtr Ptr) { Cardinal i, j; int matches = 0; if (Ptr->PointN != 4) return(0); for (i=0; i<4; i++) for (j = i+1; j<4; j++) { if (Ptr->Points[i].X == Ptr->Points[j].X) matches++; if (Ptr->Points[i].Y == Ptr->Points[j].Y) matches++; } if (matches == 4) return(1); else return(0); } It is difficult to say, but this might explain it: https://stackoverflow.com/questions/11706868/confusion-about-static-function-pointer-in-c You may need to remove the static keyword from the declaration. If you could provide complete sources (or a link to them) then perhaps someone could provide a more definitive answer. Regards, -Roberto Hi, The source is at https://www.pastebin.com/X4a4p9U2 There are many similar lines with static keyword which the compiler didn't complain about. The stackoverflow.com link suggests there is an unmatched bracket but I wasn't able to find one. Best regards, Fred
Re: compile problem on older program
On Sat, Oct 28, 2017 at 09:29:16AM -0700, Fred wrote: > Hello, > > I need to compile an older program and have a compile error. How can I > resolve this? Unfortunately I am not a C programmer although I do assembler > programming. > > Here is the output of make: > > making all in ./src... > make[1]: Entering directory '/opt/pcb-1.6.3p/src' > gcc -m32 -g -O2 -fno-strict-aliasing -Dlinux -D__i386__ > -D_POSIX_C_SOURCE=199309L -D_POSIX_SOURCE -D_XOPEN_SOURCE > -D_BSD_SOURCE -D_SVID_SOURCE > -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DFUNCPROTO=15 -DNARROWPROTO > -DRELEASE=\"1.6.3\" -DPCBLIBDIR=\"/home/cad/lib/pcb\" -DBTNMOD=\"Mod1\" > -DFONTFILENAME=\"default_font\" -DLIBRARYFILENAME=\"pcblib\" > -DGNUM4=\"/usr/bin/m4\" -DHAS_ATEXIT -DHAS_REGEX -c -o dev_rs274x.o > dev_rs274x.c > dev_rs274x.c: In function âGBX_PrintPolygonâ: > dev_rs274x.c:821:13: error: invalid storage class for function > âisRectangleâ > static int isRectangle(PolygonTypePtr Ptr); > ^ > : recipe for target 'dev_rs274x.o' failed > make[1]: *** [dev_rs274x.o] Error 1 > make[1]: Leaving directory '/opt/pcb-1.6.3p/src' > Makefile:1071: recipe for target 'all' failed > make: *** [all] Error 2 > The error is pointing to a function declaration. > > The source: > This source is for the function definition/implementation. We don't even know if this is in the same source file as the line that caused the error (which may or may not be relevant). > /* -- > * Checks a four-point polygon to see if it's a rectangle. > * Tick off pairs of X & Y coords; if we get four matches, > * we have a rectangle. > */ > static int isRectangle(PolygonTypePtr Ptr) > { > Cardinal i, j; > int matches = 0; > > if (Ptr->PointN != 4) >return(0); > > for (i=0; i<4; i++) >for (j = i+1; j<4; j++) { > if (Ptr->Points[i].X == Ptr->Points[j].X) > matches++; > > if (Ptr->Points[i].Y == Ptr->Points[j].Y) > matches++; >} > > if (matches == 4) >return(1); > else >return(0); > } > > It is difficult to say, but this might explain it: https://stackoverflow.com/questions/11706868/confusion-about-static-function-pointer-in-c You may need to remove the static keyword from the declaration. If you could provide complete sources (or a link to them) then perhaps someone could provide a more definitive answer. Regards, -Roberto -- Roberto C. Sánchez
compile problem on older program
Hello, I need to compile an older program and have a compile error. How can I resolve this? Unfortunately I am not a C programmer although I do assembler programming. Here is the output of make: making all in ./src... make[1]: Entering directory '/opt/pcb-1.6.3p/src' gcc -m32 -g -O2 -fno-strict-aliasing -Dlinux -D__i386__ -D_POSIX_C_SOURCE=199309L -D_POSIX_SOURCE -D_XOPEN_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DFUNCPROTO=15 -DNARROWPROTO -DRELEASE=\"1.6.3\" -DPCBLIBDIR=\"/home/cad/lib/pcb\" -DBTNMOD=\"Mod1\" -DFONTFILENAME=\"default_font\" -DLIBRARYFILENAME=\"pcblib\" -DGNUM4=\"/usr/bin/m4\" -DHAS_ATEXIT -DHAS_REGEX -c -o dev_rs274x.o dev_rs274x.c dev_rs274x.c: In function âGBX_PrintPolygonâ: dev_rs274x.c:821:13: error: invalid storage class for function âisRectangleâ static int isRectangle(PolygonTypePtr Ptr); ^ : recipe for target 'dev_rs274x.o' failed make[1]: *** [dev_rs274x.o] Error 1 make[1]: Leaving directory '/opt/pcb-1.6.3p/src' Makefile:1071: recipe for target 'all' failed make: *** [all] Error 2 The source: /* -- * Checks a four-point polygon to see if it's a rectangle. * Tick off pairs of X & Y coords; if we get four matches, * we have a rectangle. */ static int isRectangle(PolygonTypePtr Ptr) { Cardinal i, j; int matches = 0; if (Ptr->PointN != 4) return(0); for (i=0; i<4; i++) for (j = i+1; j<4; j++) { if (Ptr->Points[i].X == Ptr->Points[j].X) matches++; if (Ptr->Points[i].Y == Ptr->Points[j].Y) matches++; } if (matches == 4) return(1); else return(0); } I am using Jessie. Best regards, Fred Boatwright