LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-18-2007, 08:51 AM   #1
nesta
Member
 
Registered: Aug 2006
Posts: 100

Rep: Reputation: 15
GNU C and ANSI C


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.
 
Old 01-18-2007, 09:10 AM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,676
Blog Entries: 15

Rep: Reputation: 1581Reputation: 1581Reputation: 1581Reputation: 1581Reputation: 1581Reputation: 1581Reputation: 1581Reputation: 1581Reputation: 1581Reputation: 1581Reputation: 1581
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.
 
Old 01-18-2007, 09:15 AM   #3
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
There is no one sensible answer. In fact, the question sort of defies a good answer.

A base - default - distibution almost always uses glibc.

The C for Linux and GNU utilities is POSIX compliant, meaning it is based on ISO C with some minor extensions to the standard library.

GNU C can be pure ANSI, depending on the compiler switches and #define statements in the code

Do you know about SUS, POSIX, XOPEN SOURCE, .... and so on? Is that what you're talking about?
 
Old 01-18-2007, 11:42 AM   #4
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
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.
 
Old 01-18-2007, 02:50 PM   #5
nesta
Member
 
Registered: Aug 2006
Posts: 100

Original Poster
Rep: Reputation: 15
so i can conclude from your answers that :

GNU C is a standard c language while ANSI C is another standard c language.


GNU C Compiler (gcc) is a compiler for GNU C standard Language and can compile ANSI C standard by passing certain argument to gcc.

but isnt there a compiler name specified for ANSI C standard?

thanks in advance guys for my low-level questions, just correct for me anything that i have said wrong in the above statement.
 
Old 01-18-2007, 03:41 PM   #6
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Tribblix, Ubuntu/WSL
Posts: 9,761

Rep: Reputation: 459Reputation: 459Reputation: 459Reputation: 459Reputation: 459
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.
 
Old 01-18-2007, 03:48 PM   #7
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
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.
 
Old 01-18-2007, 04:00 PM   #8
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,676
Blog Entries: 15

Rep: Reputation: 1581Reputation: 1581Reputation: 1581Reputation: 1581Reputation: 1581Reputation: 1581Reputation: 1581Reputation: 1581Reputation: 1581Reputation: 1581Reputation: 1581
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.
 
Old 01-18-2007, 07:32 PM   #9
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
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
 
Old 01-20-2007, 07:05 AM   #10
nesta
Member
 
Registered: Aug 2006
Posts: 100

Original Poster
Rep: Reputation: 15
[HTML]

Originally Posted by jim mcnamara

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.

thanks in advance.
 
Old 01-20-2007, 07:52 AM   #11
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Quote:
Originally Posted by nesta
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.
 
Old 01-20-2007, 07:55 AM   #12
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Tribblix, Ubuntu/WSL
Posts: 9,761

Rep: Reputation: 459Reputation: 459Reputation: 459Reputation: 459Reputation: 459
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.

Last edited by jlliagre; 01-20-2007 at 08:41 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Ansi Telnet thebutler4 Linux - Software 1 05-25-2004 12:58 PM
Is this ansi-c compliant? xailer Programming 5 12-26-2003 08:49 PM
GNU-C to ANSI-C translator akikaniel Programming 1 11-09-2003 08:15 PM
I need GNU-C to ANSI-C translator akikaniel Linux - Newbie 1 11-09-2003 02:24 PM
images to ansi jayakrishnan Linux - General 1 06-06-2002 10:20 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:54 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration