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
16
votes
6 answers

What parts of C are most portable?

I recently read an interview with Lua co-creators Luiz H. de Figueredo and Roberto Ierusalimschy, where they discussed the design, and implementation of Lua. It was very intriguing to say the least. However, one part of the discussion brought…
Miguel
  • 1,966
  • 2
  • 18
  • 32
16
votes
3 answers

Casting an int pointer to a char ptr and vice versa

The problem is simple. As I understand, GCC maintains that chars will be byte-aligned and ints 4-byte-aligned in a 32-bit environment. I am also aware of C99 standard 6.3.2.3 which says that casting between misaligned pointer-types results in…
LearnerForever
  • 161
  • 1
  • 1
  • 3
16
votes
2 answers

Are there any differences between ANSI C and ISO C?

I understand that there is both an ANSI standard and an ISO standard for C. Are there any differences between these two standards? If so, what are they? And if there is not a difference then what's the point of having two standards?
Earlz
  • 62,085
  • 98
  • 303
  • 499
16
votes
2 answers

ANSI C (ISO C90): Can scanf read/accept an unsigned char?

Simple question: Can scanf read/accept a "small integer" into an unsigned char in ANSI C? example code un_char.c: #include #include int main(void) { unsigned char character; scanf("%hhu", &character); return…
Tim
  • 161
  • 1
  • 3
16
votes
3 answers

"int" really required to be at least as large as "short" in C?

I've read a couple of times in different sources (e.g. Wikipedia: http://en.wikipedia.org/wiki/C_variable_types_and_declarations#Size), that in C, a long long is not smaller than a long, which is not smaller than an int, which is not smaller than a…
Hermann Speiche
  • 894
  • 1
  • 9
  • 16
16
votes
4 answers

Is returning va_list safe in C?

I'd like to write a function that has return type of va_list. example: va_list MyFunc(va_list args); is this safe and portable?
Hayri Uğur Koltuk
  • 2,970
  • 4
  • 31
  • 60
15
votes
3 answers

What C program behaves differently in run-time when compiled with C89 and C99?

I found the following snippet (I think in Wikipedia) that creates a different run-time when C++ comments are recognized than when not: int a = 4 //* This is a comment, but where does it end? */ 2 ; But until now that's been the only one (variants…
Johan Bezem
  • 2,582
  • 1
  • 20
  • 47
15
votes
3 answers

How to rewrite C-struct designated initializers to C89 (resp MSVC C compiler)

guys, I've this problem: Normally in C99 GCC (cygwin / MinGW / linux), there is dot-notation syntax for initializers in C struct. Like this: //HELP ME HOW TO REWRITE THIS (in most compact way) to MSVC static struct my_member_t my_global_three[] = { …
DinGODzilla
  • 1,611
  • 4
  • 21
  • 34
15
votes
2 answers

Is it safe to cast size_t to unsigned long int?

I need a portable way to print the value of a variable n of type size_t. Since I use ANSI C89 I cannot use the z length modifier. My current approach is to cast the value to long unsigned int: printf("%lu\n", (long unsigned int) n); Provided that…
August Karlstrom
  • 10,773
  • 7
  • 38
  • 60
15
votes
2 answers

Is omitting return statement undefined behaviour in C89 (aka ANSI C)?

Consider following basic example: #include int main(void) { printf("Hi there!\n"); } Does it invoke undefined behaviour in C89? I tried to get some sense from this question, but most upvoted answers claim that it's…
Grzegorz Szpetkowski
  • 36,988
  • 6
  • 90
  • 137
15
votes
2 answers

GCC options for strict C90 code?

I am trying to find what is the combination of gcc flags to use when testing strict C90 conformance. According to previous post: GCC options for strictest C code?, I should only need a --std=c90. However here is what I tried: $ cat t.c #include…
malat
  • 12,152
  • 13
  • 89
  • 158
15
votes
4 answers

Does ANSI-C not know the inline keyword?

When compiling something as simple as inline int test() { return 3; } int main() { test(); return 0; } with gcc -c test.c, everything goes fine. If the -ansi keyword added, gcc -ansi -c test.c, one gets the error message test.c:1:8: error:…
Nico Schlömer
  • 53,797
  • 27
  • 201
  • 249
14
votes
5 answers

C check if file exists

In a project I have to do in C89 standard I have to check if a file exists. How do I do this? I thought of using FILE *file; if ((file = fopen(fname, "r")) == NULL) { printf("file doesn't exists"); } return 0; but I think there can be more cases…
The GiG
  • 2,571
  • 2
  • 28
  • 29
14
votes
5 answers

Should I place the parameter storage class specifier in the function definition or in both the declaration and definition?

I'm working on porting some old K&R code to ANSI C, so I'm writing missing function prototype declarations. A lot of the function definitions have parameters with the register storage class, but I'm not sure if the register storage class specifier…
14
votes
2 answers

Are all of the features of C99 also in C++?

This page lists 53 features that were new in C99 (i.e they are in C99 but not C89). Are all of these features also in C++? Even C++98? If not, which of the features are in C++ and which are not?
user200783
  • 13,722
  • 12
  • 69
  • 135