ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
hi folks,
i want to know what is the difference between :
1)ANSI C and GNU C and which one is used on our linux home PCs
2)glibc and uclibc which one is used on our linux home PCs
thanks in advance.
GNU C (gcc) is the one you get by default with Linux.
ANSI C as implied by the name is an ANSI compliant version of C and usually costs $$$. Some UNIX flavors (e.g. HP-UX) come with a rudimentary C compiler for doing things like recompiling the kernel but make you pay for ANSI C for full scale development work.
Of course you can get gcc for most UNIX flavors so depending on what you're doing you might not need ANSI C. For commercial UNIX app building you'd probably want to make it with ANSI C to make it salable.
ANSI C is a standardised version of the C language. As with all such standards it was intended to promote compatibility between different compilers which tended to treat some things a little differently, leading to vendor lock in and programmers losing sleep when they tried to port software from one system to another.
Passing the -ansi option to gcc (the GNU C Compiler) tells it to work in ANSI mode - i.e. to return an error when it sees code which is not ANSI-C standards compliant.
gcc actually supports many standards. Read the gcc manual page and search for the -std= option.
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789
Rep:
Quote:
Originally Posted by nesta
so i can conclude from your answers that :
GNU C is a standard c language while ANSI C is another standard c language.
Nope.
ANSI C is a Standard (i.e. the formal description of, in this case, a programming language) while Gnu C is an implementation of a compiler which happen to implements this ANSI C Standard along with some proprietary extensions.
The previous C standard before ANSI C is known to be the K&R Standard.
There are many ANSI C compilers. GNU C (gcc) does a lot of stuff beyond ANSI.
There is no "compiler name" specified for the C standard.
ANSI is an list of "how it must be done" things. Not a brand of compiler.
GNU is NOT a standard, it's one of many compilers.
Standards are worked on by a large committee for years, reviewed and then set into "stone" and published. Compiler developers have to pretty much prove their compiler adheres to those standards to claim ANSI support.
The current ISO C (ANSI) C standard is C99. There is one for COBOL, FORTRAN, etc.
ANSI is a language standard that says how the compiler has to deal with each word in a line of code. It does not specify how to deal with the command word or operator internally, just what the result has to be. The internal part of dealing with a command/operator/symbol is called the implementation.
On HP-UX at least they sell the C bundle under the name "ANSI C". I agree ANSI is a standards specification but in the HP-UX world when one talks about ANSI C they're more apt to be talking about the product they bought from HP rather than the standard. It is usually used to distinguish between that and the "kernel compiler" that comes without cost and is very rudimentary as it is designed only for compiling the HP-UX kernel. It may be marketing things like this that lend to the confusion.
I tell you what... I'll "sell" you an installation of ANSI C, GNU style. You send me the cash and then add 'alias gcc="gcc -ansi"' to your .bash_profile
ANSI is a language standard that says how the compiler has to deal with each word in a line of code. It does not specify how to deal with the command word or operator internally, just what the result has to be.The internal part of dealing with a command/operator/symbol is called the implementation.
[/HTML]
Actually,i did not understand. Can u give me a very simple example ?
bescause i know that ANSI C is a standard which means it has certain header files and library file isnt it? so how it can tell the compiler the result of a line code? i dont understand.
Actually,i did not understand. Can u give me a very simple example ?
The standard will explain what should happen when the programmer does the following:
Code:
int cnt;
That is a variable is created that can at least hold an integer number in the range... well the standard actually says:
Quote:
A ‘‘plain’’ int object has the natural size suggested by the architecture of the execution environment (large enough to contain any value in the range INT_MIN to INT_MAX as defined in the header <limits.h>)
So what an integer will hold is decided by the compiler which will take the architecture of the target machine into account (32-bit, 64-bit architecture etc)
I hope that helps there are many other bits of the language that are left to the compiler writer. What the standard tries to do is limit the confusion when it leaves the interpretation to the discretion of the compiler writer. One area where results will differ from one compiler to another is with the following line:
Code:
int total = cnt++ * ++cnt;
This is because to use the increment operation on the same variable more than once on the same line is undefined, and left to the compiler to interpret in it's own way.
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789
Rep:
Quote:
Originally Posted by nesta
bescause i know that ANSI C is a standard which means it has certain header files and library file isnt it?
No, a standard doesn't "have certain header files", it specifies, beyond other things, what these files must contain and that these files are required by an implementation that support this standard.
For example, a standard defines what a DVD is, its diameter, how the data is laid out on it, and so on.
A standard compliant DVD reader is able to read a DVD because it complies with the standard, but is not to be confused with the standard itself, which is only a bunch of paper documents.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.