Skip to content
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

Open
kakaroto opened this issue Jun 3, 2011 · 13 comments
Open

netdb.h location and compilation issues with ansi/pedantic flags #28

kakaroto opened this issue Jun 3, 2011 · 13 comments

Comments

@kakaroto
Copy link
Member

kakaroto commented Jun 3, 2011

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 :

/usr/local/ps3dev/psl1ght/ppu/include/ppu-types.h:107:1: error: expected identifier or '(' before '/' token
  In file included from /usr/local/ps3dev/psl1ght/ppu/include/netdb.h:4:0,
                 from http_fetcher.c:26:
/usr/local/ps3dev/psl1ght/ppu/include/net/socket.h:13:7: warning: ISO C90 does not support flexible array members
/usr/local/ps3dev/psl1ght/ppu/include/net/socket.h:25:2: error: expected specifier-qualifier-list before 'socklen_t'
/usr/local/ps3dev/psl1ght/ppu/include/net/socket.h:35:2: error: expected specifier-qualifier-list before 'socklen_t'
/usr/local/ps3dev/psl1ght/ppu/include/net/socket.h:33:8: warning: struct has no members
/usr/local/ps3dev/psl1ght/ppu/include/net/socket.h:98:50: error: expected declaration specifiers or '...' before 'socklen_t'
/usr/local/ps3dev/psl1ght/ppu/include/net/socket.h:99:54: error: expected declaration specifiers or '...' before 'socklen_t'
/usr/local/ps3dev/psl1ght/ppu/include/net/socket.h:100:57: error: expected declaration specifiers or '...' before 'socklen_t'
/usr/local/ps3dev/psl1ght/ppu/include/net/socket.h:101:55: error: expected declaration specifiers or '...' before 'socklen_t'
/usr/local/ps3dev/psl1ght/ppu/include/net/socket.h:102:55: error: expected declaration specifiers or '...' before 'socklen_t'
/usr/local/ps3dev/psl1ght/ppu/include/net/socket.h:103:75: error: expected declaration specifiers or '...' before 'socklen_t'
/usr/local/ps3dev/psl1ght/ppu/include/net/socket.h:106:92: error: expected declaration specifiers or '...' before 'socklen_t'
/usr/local/ps3dev/psl1ght/ppu/include/net/socket.h:109:108: error: expected declaration specifiers or '...' before 'socklen_t'
In file included from /usr/local/ps3dev/psl1ght/ppu/include/netdb.h:4:0,
                 from http_fetcher.c:26:
/usr/local/ps3dev/psl1ght/ppu/include/net/socket.h:111:81: error: expected declaration specifiers or '...' before 'socklen_t'
In file included from http_fetcher.c:26:0:
/usr/local/ps3dev/psl1ght/ppu/include/netdb.h:30:48: error: expected declaration specifiers or '...' before 'socklen_t'
In file included from /usr/local/ps3dev/psl1ght/ppu/include/netinet/in.h:35:0,
                 from http_fetcher.c:28:
/usr/local/ps3dev/psl1ght/ppu/include/arpa/inet.h:23:59: error: expected declaration specifiers or '...' before 'socklen_t'
In file included from http_fetcher.c:30:0:
/usr/local/ps3dev/psl1ght/ppu/include/sys/socket.h:15:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before 's32'
/usr/local/ps3dev/psl1ght/ppu/include/sys/socket.h:21:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before 's32'
/usr/local/ps3dev/psl1ght/ppu/include/sys/socket.h:27:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before 's32'
/usr/local/ps3dev/psl1ght/ppu/include/sys/socket.h:33:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before 's32'
/usr/local/ps3dev/psl1ght/ppu/include/sys/socket.h:39:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before 's32'
/usr/local/ps3dev/psl1ght/ppu/include/sys/socket.h:45:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before 's32'
/usr/local/ps3dev/psl1ght/ppu/include/sys/socket.h:51:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before 's32'
/usr/local/ps3dev/psl1ght/ppu/include/sys/socket.h:57:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before 's32'
/usr/local/ps3dev/psl1ght/ppu/include/sys/socket.h:63:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before 's32'
@zeldin
Copy link
Member

zeldin commented Jun 3, 2011

Why not use //? It's valid C99, which is the current C standard. -ansi selects an obsolete C standatd, use -std=c99 instead.

@kakaroto
Copy link
Member Author

kakaroto commented Jun 3, 2011

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.

@ooPo
Copy link
Member

ooPo commented Jun 4, 2011

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.

@kakaroto
Copy link
Member Author

kakaroto commented Jun 4, 2011

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.
The argument here is that it's good practice to write C89 to make sure your code is always portable, while in this case, it's PSL1GHT, so you don't care about portability, it still remains good practice.
The main argument though is that for apps/games/libraries that use -ansi in CFLAGS, and they work on every platform, they should also work with PSL1GHT without being forced to remove that flag just so they compile with PSL1GHT. Like I said, if it was for some homebrew app, code it the way you want, but for standard header files from the SDK, that's unacceptable.
Also, this '//' versus '/**/' is just one of the things that need fixing, what do you think of declaring char buffer[]; ? that simply isn't right, I didn't even know that C99 allowed to declare an array without specifying its size. That sort of thing must be fixed.

@ooPo
Copy link
Member

ooPo commented Jun 4, 2011

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.

@zeldin
Copy link
Member

zeldin commented Jun 4, 2011

C89 is not the "real, original C language", that's K&R C. In that language, you had to write prototypes like this:

int foo(bar, gazonk)
  int bar;
  char *gazonk:
{
}

Being able to write

int foo(int bar, char *gazonk)
{
}

is an "extension" standardized by C89, and was borrowed from ALGOL 68, so by your reasoning we should not use it? ;-)
(There are some people who do follow that practice, mind...)

@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...

@zeldin
Copy link
Member

zeldin commented Jun 4, 2011

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

struct s { int z; int w[]; };
struct s * p = malloc(sizeof(struct s)+sizeof(int)*7);

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.

@zeldin
Copy link
Member

zeldin commented Jun 4, 2011

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).

@kakaroto
Copy link
Member Author

kakaroto commented Jun 4, 2011

@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.
Either way, my point remains.. if a normal system's header is ANSI, then PSL1GHT's header should also follow ANSI, otherwise we break portability. I see absolutely no justification not to do it.
Anyways, it seems that all this talk about ANSI C vs. C99 made us skip the issue with netdb.h location. Any comments on that ? Or would you prefer I file a separate issue for it?

@zeldin
Copy link
Member

zeldin commented Jun 4, 2011

  • C99 is also "ANSI C", it was adopted by ANSI in May 2000.
  • int w[0]; is not in any C standard. That's a GCC extension.

Yes, I also think netdb.h should be in the standard location. I had to patch SDL_net because of this...

@kraiskil
Copy link

kraiskil commented Jun 6, 2011

BTW - psl1ght already assumes -std=gnu99 at places

@Spork-Schivago
Copy link

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.

@Spork-Schivago
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants