Questions tagged [ansi-c]

ANSI C is an informal term sometimes used when referring to the C programming language standard published by the American National Standards Institute (ANSI) in 1989 .

"ANSI C" is an informal term used to refer to the 1989 version of the C language. The formal name for this version of the language is ISO/IEC 9899:1990. Informally it is also known as "C89" or "C90".

This is because the American National Standards Institute (ANSI) first published this standard in the year 1989, as a national standard for the USA. It became international ISO standard in the year 1990. So ANSI C, C89 and C90 all refer to the same technical standard.

It is a common misunderstanding that "ANSI C" means standard compliant C. The ANSI standard institute haven't had anything to do with C since 1989. The language is maintained by ISO SC22/WG14. Yet the term "ANSI C" is sometimes used to mean standard compliant, particularly in old books and by old compilers.

Because of this ambivalent meaning, please avoid using this tag. For questions regarding the C89/C90 version of the C language, please use . For questions regarding standard-compliant C, simply use the tag.

Further information about the different C standard versions.

618 questions
173
votes
37 answers

How to convert an enum type variable to a string?

How to make printf to show the values of variables which are of an enum type? For instance: typedef enum {Linux, Apple, Windows} OS_type; OS_type myOS = Linux; and what I need is something like printenum(OS_type, "My OS is %s", myOS); which must…
psihodelia
  • 29,566
  • 35
  • 108
  • 157
161
votes
5 answers

What is the difference between C, C99, ANSI C and GNU C?

I have started programming practice on codechef and have been confused by the difference between C and C99. What does C mean here? Is it C89? Check the languages at the bottom of this submit. It contains both C and C99. I found on the internet…
Aseem Bansal
  • 6,722
  • 13
  • 46
  • 84
129
votes
10 answers

Why doesn't ANSI C have namespaces?

Having namespaces seems like no-brainer for most languages. But as far as I can tell, ANSI C doesn't support it. Why not? Any plans to include it in a future standard?
Pulkit Sinha
  • 2,654
  • 4
  • 19
  • 20
102
votes
5 answers

Where can one find the C89/C90 standards in PDF format?

I’m looking for a free copy version of the C89/C90 standard, but I can’t find it anywhere! Why is so hard to find it? C99 and C11 standards are very easy to get a copy of on Internet. Even in the Stack Overflow questions Where do I find the current…
The Mask
  • 17,007
  • 37
  • 111
  • 185
54
votes
4 answers

String termination - char c=0 vs char c='\0'

When terminating a string, it seems to me that logically char c=0 is equivalent to char c='\0', since the "null" (ASCII 0) byte is 0, but usually people tend to do '\0' instead. Is this purely out of preference or should it be a better…
Joe DF
  • 5,438
  • 6
  • 41
  • 63
54
votes
4 answers

What is the significance of January 1, 1601?

This structure is a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601. Reference: http://msdn.microsoft.com/en-us/library/aa915351 Why it is set "since 1601"? Why not unix time 1970 or even 2000? What can I…
zakrzak
  • 543
  • 1
  • 4
  • 7
35
votes
2 answers

What does static mean in ANSI-C

Possible Duplicate: What does “static” mean in a C program? What does the static keyword mean in C ? I'm using ANSI-C. I've seen in several code examples, they use the static keyword in front of variables and in front of functions. What is the…
Sency
  • 2,818
  • 8
  • 42
  • 59
33
votes
4 answers

ANSI C vs other C standards

On several compilers I have used (all gcc but various versions) I get a C99 mode error for things like declaring int i inside the for loop expression instead of before it (if I do not use the std=c99 option). After reading here I understand that…
ubiquibacon
  • 10,451
  • 28
  • 109
  • 179
31
votes
2 answers

GCC options for strictest C code?

What GCC options should be set to have GCC as strict as possible? (and I do mean as strict as possible) I'm writing in C89 and want my code to be ANSI/ISO compliant.
user1149305
29
votes
5 answers

Who defines C operator precedence and associativity?

Introduction In every textbook on C/C++, you'll find an operator precedence and associativity table such as the following: http://en.cppreference.com/w/cpp/language/operator_precedence One of the questions on StackOverflow asked something like…
Fiddling Bits
  • 8,712
  • 3
  • 28
  • 46
25
votes
8 answers

ANSI C equivalent of try/catch?

I have some C code I'm working with, and I'm finding errors when the code is running but have little info about how to do a proper try/catch (as in C# or C++). For instance in C++ I'd just do: try{ //some stuff } catch(...) { //handle error } but…
aiden
  • 259
  • 1
  • 3
  • 3
24
votes
2 answers

fopen for everything - is this possible?

I used to programing windows, but I want to try my hand on making a cross-platform application. And I have some questions, if you don't mind: Question 1 Is there some way to open UNICODE\ASCII file and automatically detect it's encoding using bare…
Anonymous
  • 347
  • 2
  • 8
24
votes
2 answers

Can I return a initialized struct on one line in ANSI C?

I just wanna know if I can do something like that... typedef struct Result{ int low, high, sum; } Result; Result test(){ return {.low = 0, .high = 100, .sum = 150}; } I know that is the wrong way, but can I do that or I need to create a local…
João Esteves
  • 341
  • 2
  • 3
23
votes
1 answer

Difference between char* var; and char *var;?

Just wondering if there's any difference between: char* var; char *var; or is it just a matter of preference (spacing)?
Joe DF
  • 5,438
  • 6
  • 41
  • 63
22
votes
1 answer

Is the first field of a C structure always guaranteed to be at offsetof 0?

Regarding the C programming language... Part of the question at C/C++ Structure offset states that "& does not always point at the first byte of the first field of the structure" But looking over the "ANSI Rationale" at…
user2088639
1
2 3
41 42