Questions tagged [c89]

This tag is for questions regarding the international standard ISO 9899:1990, also known as "C89", "C90" or "ANSI C", with amendments and technical corrigenda (as opposed to K&R C, C99, C11 or later C standard revisions).

The first C standard was released 1989 nationally in USA, by their national standard institute ANSI. This release is called C89 or ANSI-C. One year later, the American standard was accepted internationally and published by ISO (ISO 9899:1990). This release is called C90. Technically, it is the same standard as C89/ANSI-C, though formally, C90 replaced C89/ANSI-C, making them obsolete.

Always use the tag for all your C questions, then complement it with the tag for questions that are specific to this version of the standard.

643 questions
271
votes
6 answers

What is the behavior of integer division?

For example, int result; result = 125/100; or result = 43/100; Will result always be the floor of the division? What is the defined behavior?
T.T.T.
  • 33,367
  • 47
  • 130
  • 168
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
145
votes
8 answers

Variable declaration placement in C

I long thought that in C, all variables had to be declared at the beginning of the function. I know that in C99, the rules are the same as in C++, but what are the variable declaration placement rules for C89/ANSI C? The following code compiles…
mcjabberz
  • 9,788
  • 10
  • 36
  • 38
131
votes
3 answers

How does the below program output `C89` when compiled in C89 mode and `C99` when compiled in C99 mode?

I've found this C program from the web: #include int main(){ printf("C%d\n",(int)(90-(-4.5//**/ -4.5))); return 0; } The interesting thing with this program is that when it is compiled and run in C89 mode, it prints C89 and…
Spikatrix
  • 20,225
  • 7
  • 37
  • 83
123
votes
8 answers

Is the "struct hack" technically undefined behavior?

What I am asking about is the well known "last member of a struct has variable length" trick. It goes something like this: struct T { int len; char s[1]; }; struct T *p = malloc(sizeof(struct T) + 100); p->len = 100; strcpy(p->s, "hello…
Evan Teran
  • 87,561
  • 32
  • 179
  • 238
109
votes
10 answers

Why should you use strncpy instead of strcpy?

Edit: I've added the source for the example. I came across this example: char source[MAX] = "123456789"; char source1[MAX] = "123456789"; char destination[MAX] = "abcdefg"; char destination1[MAX] = "abcdefg"; char *return_string; int index = 5; /*…
Kredns
  • 36,461
  • 52
  • 152
  • 203
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
97
votes
29 answers

Is there any reason to use C instead of C++ for embedded development?

Question I have two compilers on my hardware C++ and C89 I'm thinking about using C++ with classes but without polymorphism (to avoid vtables). The main reasons I’d like to use C++ are: I prefer to use “inline” functions instead of macro…
Piotr Czapla
  • 25,734
  • 24
  • 99
  • 122
80
votes
4 answers

Is the behavior of subtracting two NULL pointers defined?

Is the difference of two non-void pointer variables defined (per C99 and/or C++98) if they are both NULL valued? For instance, say I have a buffer structure that looks like this: struct buf { char *buf; char *pwrite; char *pread; } ex; Say,…
John Luebs
  • 861
  • 6
  • 8
55
votes
6 answers

Are prototypes required for all functions in C89, C90 or C99?

To be truly standards-compliant, must all functions in C (except for main) have a prototype, even if they are only used after their definition in the same translation unit?
Sydius
  • 13,567
  • 17
  • 59
  • 76
50
votes
4 answers

How to generate NaN, -Infinity and +Infinity in ANSI C?

I use ANSI C89 (not C++), and I want to generate NaN, -Infinity and +Infinity. Is there any standard way (eg. standard macro)? Or is there any platform and compiler independent way to generate these numbers? float f = 0.0 / 0.0; // Is f ALWAYS in…
Amir Saniyan
  • 13,014
  • 20
  • 92
  • 137
48
votes
11 answers

What are the major differences between ANSI C and K&R C?

The Wikipedia article on ANSI C says: One of the aims of the ANSI C standardization process was to produce a superset of K&R C (the first published standard), incorporating many of the unofficial features subsequently introduced. However, the…
Thomas Owens
  • 114,398
  • 98
  • 311
  • 431
47
votes
6 answers

Why was mixing declarations and code forbidden up until C99?

I have recently become a teaching assistant for a university course which primarily teaches C. The course standardized on C90, mostly due to widespread compiler support. One of the very confusing concepts to C newbies with previous Java experience…
RavuAlHemio
  • 2,331
  • 19
  • 22
47
votes
11 answers

Why didn't C have a boolean data type prior to C99?

I realise you can just #define some integers, but why didn't C have a dedicated boolean data type before C99? It's such a common occurence in programming and logic, I don't understand the absense of an explicit type and notation.
xyz
  • 27,223
  • 29
  • 105
  • 125
43
votes
7 answers

How to find my current compiler's standard, like if it is C90, etc

I'm working on a Linux machine. Is there any system command to find the standard followed by the C compiler I'm using?
Hemanth
  • 5,035
  • 9
  • 41
  • 59
1
2 3
42 43