![]() |
| | #1 |
| Registered User Join Date: Jun 2009
Posts: 5
| I use Linux with gcc 4.2.3 (I can upgrade the version, no problem) my problem is with C standards, here is what I know: there are currently two standards of C implemented c89 and gnu89, and two not yet fully implemented c99 and gnu99 gnu89 is the default now, gnu99 will be the default in the future. my question: which standard should I use (I guess it's gnu89)? and what is the standard in which most apps are coded in, for example the linux kernel is coded in which one? I want my code to be compatible at least under all Linux distros, but I would also like if it compiles under other operating systems too. also if someone will recommend a standard, what book should I use as a reference for that standard ("C complete reference" is good for C89 and C99, but what about the GNU extensions in gnu89/99 ?) Thanks in advance. |
| AMAMH is offline | |
| | #2 |
| Registered User Join Date: Jan 2008 Location: Seattle
Posts: 476
| |
| slingerland3g is offline | |
| | #3 |
| and the Hat of Guessing Join Date: Nov 2007
Posts: 8,740
| More to the point, gnu89/gnu99 aren't standards, they are the GCC compiler extensions to the standard. |
| tabstop is offline | |
| | #4 | |
| subminimalist Join Date: Jul 2008 Location: NYC
Posts: 3,944
| Quote:
The Open Group Base Specifications Issue 7 if you look under alphabetical index, this is just the manual pages for all standard C functions as implemented under POSIX. They are pretty good man pages too. Generally, tho, just use the GNU C Reference The GNU C Library since your C library is built by GNU, and they do include explicit notes there about "gnu extensions" that may effect portability. Portability issues are specific issues. You will become aware of them as they become involved with your programs, don't worry. For now, you do not need to add any compiler flags except this one: gcc -Wall That will help to keep your code proper and as portable as possible, eg it will warn you when you use a gnu specific extension like this: warning: implicit declaration of function ‘strcasestr’ because GNU's strcasestr is GNU specific.
__________________ Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS | |
| MK27 is offline | |
| | #5 |
| Registered User Join Date: Jun 2009
Posts: 5
| thanks MK27 for ur reply. u really helped me, especially for pointing that I should use -Wall to disable gnu extensions, but isn't gcc available for all operating systems? I mean why disable its extensions if I know that it's kinda portable too. Anyway, since I see that flag a lot "-Wall" while compiling programs from source it must be important, I will likely use it. thanks also for the GNU reference and POSIX reference. I think for now I will just use the default gcc standard (gnu89) and more likely with gnu extensions disabled, I think this is equivalent to -std=c89, but I will just use -Wall. |
| AMAMH is offline | |
| | #6 | |
| subminimalist Join Date: Jul 2008 Location: NYC
Posts: 3,944
| Quote:
To make a long story short, if you run across that warning because of a library function (not your own*) and you want to get rid of it and still compile with -Wall, just copy the prototype from the manual into your program code at the top: Code: char * strcasestr (const char *haystack, const char *needle); warning: strcasestr is a GNU specific extension to the C standard would have been fine. In any case, "forcing" you to copy the prototype in does serve as a strong reminder of the fact that that function may have limited portability. There are actually not many functions like that, strcasestr is the only one I could think of off the top of my head. And yes, gcc is available for available for more OS's than I've ever heard of. I don't think it has to use the GNU C library to work; certainly MS users use it and they are not using the GNU library. It is good you are thinking pro-actively, but don't sweat about this stuff too much right now. * if it's because of your own function you forgot to include a prototype: that is the original meaning of "warning: implicit declaration..."
__________________ Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS Last edited by MK27; 06-14-2009 at 02:29 PM. | |
| MK27 is offline | |
| | #7 |
| Registered User Join Date: Jun 2009
Posts: 5
| well, I was lazy and didn't read the manual. Actually -Wall is just "warnings all", it's not about gnu extensions specifically. still it's good to use it, if not to make sure the code has no errors at least it will make me know more about the language,compiler,etc |
| AMAMH is offline | |
| | #8 |
| Registered User Join Date: Apr 2008 Location: Haddock, GA, United States
Posts: 13
| Good C programming books! If you're a C beginner, I think you should buy C Primer Plus Fifth Edition by Stephan Prata, and after you finish reading that one, you can also buy The C Programming Language Second Edition by Kernighan and Ritchie. I think the two books mentioned are really good for learning and mastering C. Well, mastering actually comes with a lot of practice, like any other thing. I hope you'll enjoy reading them, if you are going to buy the two books I recommended. Good luck, and if you're willing to have a study partner, I'm also studying C myself, etc. Goodbye for now, and I will talk to you soon. |
| adrian.mowrey is offline | |
| | #9 |
| Registered User Join Date: Jun 2009
Posts: 5
| I don't think u understand my point the new c standard (which is actually about 10 years old) is not completely implemented in gcc and a book like "The C Programming Language" was released before c99. my question is: should I just ignore the c99 standard and use the default gnu89 or c89? is c99 implemented enough in gcc that I can use it? I know that u can see the current status of c99 in gcc on its website but it's too technical for me. Actually c99 is planned to be the next default in gcc, so I can't just ignore it, besides, I HATE living in the past. |
| AMAMH is offline | |
| | #10 |
| Registered User Join Date: Jun 2009
Posts: 5
| update: I think actually my question is just like having a chat, it's not important to begin programming in C. I will just use c99 as it's currently implemented in gcc (gcc 4.4.0) and I will use "C The Complete Reference" as my reference. |
| AMAMH is offline | |
| | #11 | |||
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,354
| Quote:
Quote:
Quote:
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | |||
| laserlight is online now | |
![]() |
| Tags |
| gcc, linux, question, standard |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Run time differences in Linux gcc versions | circuitbreaker | C++ Programming | 7 | 02-14-2008 11:09 PM |
| gcc configuration under linux advice needed | vart | Tech Board | 9 | 01-10-2007 02:46 PM |
| Question about Linux Firewall | naruto | Linux Programming | 6 | 07-25-2004 12:39 PM |
| question from linux board ( not os dependant ) | crypto | C Programming | 4 | 11-15-2002 02:09 AM |
| Question about LINUX | River21 | A Brief History of Cprogramming.com | 0 | 09-17-2001 06:39 PM |