-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
netdb.h location and compilation issues with ansi/pedantic flags #28
Comments
Why not use //? It's valid C99, which is the current C standard. -ansi selects an obsolete C standatd, use -std=c99 instead. |
because '//' is C++ syntax not C, and even if it's in C99 standard, it still use borrowed from C++. Also, because many people use -ansi -pedantic and we shouldn't have to modify their flags just to get it to compile... If it was for some homebrew app, then do whatever you want, but if it's for standard socket.h files from the toolchain, then it should follow the strictest C standard. |
C99 is a C standard, so that's a terrible point. A better reason against using // would be that gcc isn't using C99 by default. A better solution would be to get gcc to use C99 by default so it will support more code with fewer problems. |
By "standard C" I meant ansi C, the real, original C language, not the C99 standard which added some 'extensions' to the language. And no, gcc does use C99 by default, but not if you give it -ansi argument which some apps/libraries use to make sure they are portable. |
I'd much rather see everyone use the latest standard, but if you want to modify it to bulid nicely in all standards then I certainly don't mind. |
C89 is not the "real, original C language", that's K&R C. In that language, you had to write prototypes like this:
Being able to write
is an "extension" standardized by C89, and was borrowed from ALGOL 68, so by your reasoning we should not use it? ;-) @ooPo: Hm, yes you are right, it seems like gnu90 is still the gcc default, not gnu99. According to the manpage they will switch "When ISO C99 is fully implemented in GCC". Huh. They are 12 years behind schedule so far... |
Oh, and regarding arrays without size, that is definitiely in the C standard. You've always been able to declare arrays without size, that's called an "incomplete array type". So you can only use it in declarations, not definitions. You can say "extern int bah[];" and it means that there is an int array called bah defined somewhere else, but you don't know (or won't tell) how big it is. What's new in C99 is that you can put such an incomplete array type at the end of a struct declaration (see §6.7.2.1:16 of the standard), meaning that the array will not add to the size of the struct, but you can manually add elements to the malloc call, so with the following code
it will be valid to access p->w[0] through p->w[6]. This is a very useful feature. With C90 you had to declare w of size 1, and either remember to subtract that in the allocation or live with the wasted heap. C99 also features array definitions where the size is not a constant, but I don't think we use that. |
BTW, I agree with ooPo, if you want to convert the POSIX-ish headers to C90, then please go ahead. I think the places were we really need C99 (or equivalent GNU extensions) is limited to the non-POSIX headers (such as <rsx/gcm_sys.h>, which uses restrict, and <rsx/rsx.h> which uses inline). |
@zeldin, I did say "ANSI C" which is C89 (and C90, not K&R). And regarding the variable array, I know about it, but you'd usually put int w[0]; and not int w[];.. at least, that's how I remember it. |
Yes, I also think netdb.h should be in the standard location. I had to patch SDL_net because of this... |
BTW - psl1ght already assumes -std=gnu99 at places |
I replaced all the // with /* */ in all of psl1ght. Would anyone want the patch file? I also replaced the {NULL}'s with NULL in psl1ght/ppu/sprx/libnet/socket.c because I was receiving a lot of warnings about braces around scalar initialize. The problem is there are braces around single variables. For example {variable1, variable2, {variable3}, variable4}. I am using a newer compiler though then the one included with the PS3 Toolchain. |
I modified the code in my https://github.com/Spork-Schivago/PSL1GHT and replaced all the //...'s with /* ... */. You can merge it now if you want. It should be in that pull request I sent a few days ago. |
I was trying to compile http_fetcher library (since there are no docs for the http API in psl1ght) and I noticed these issues :
1 - netdb.h is not installed correctly, it's in psl1ght/ppu/include/net/netdb.h but the standard is to include <netdb.h> and not <net/netdb.h>. So this either forces me to add -I$(PSL1GHT)/ppu/include/net to the CFLAGS or to copy netdb.h into ppu/include directly. Is this normal? is it expected that I add the -I flag? Shouldn't those standard header files (I'm thinking socket.h too)
2 - by default http_fetcher uses the "-ansi -pedantic" flags (which I can disable with --disable-strict so all is good), and it shows a few issues with the code in ppu-types.h and socket.h... the most annoying one is that you should never use '//' for comments, and always use /* instead */ (annoying because it will be boring to fix)... Anyways, here are the errors I got :
The text was updated successfully, but these errors were encountered: