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
43
votes
7 answers

What's the difference between "int" and "int_fast16_t"?

As I understand it, the C specification says that type int is supposed to be the most efficient type on target platform that contains at least 16 bits. Isn't that exactly what the C99 definition of int_fast16_t is too? Maybe they put it in there…
something_clever
  • 806
  • 1
  • 7
  • 17
35
votes
6 answers

Type to use to represent a byte in ANSI (C89/90) C?

Is there a standards-complaint method to represent a byte in ANSI (C89/90) C? I know that, most often, a char happens to be a byte, but my understanding is that this is not guaranteed to be the case. Also, there is stdint.h in the C99 standard, but…
Sydius
  • 13,567
  • 17
  • 59
  • 76
33
votes
5 answers

Enabling VLAs (variable length arrays) in MS Visual C++?

How can I enable the use of VLAs, variable length arrays as defined in C99, in MS Visual C++ or that is not possible at all? Yes I know that the C++ standard is based on C89 and that VLAs are not available in C89 standard and thus aren't available…
Shinnok
  • 6,279
  • 6
  • 31
  • 44
33
votes
3 answers

How to sum large numbers?

I am trying to calculate 1 + 1 * 2 + 1 * 2 * 3 + 1 * 2 * 3 * 4 + ... + 1 * 2 * ... * n where n is the user input. It works for values of n up to 12. I want to calculate the sum for n = 13, n = 14 and n = 15. How do I do that in C89? As I know, I can…
Timʘtei
  • 753
  • 1
  • 8
  • 21
30
votes
4 answers

Using M_PI with C89 standard

I'm using C and trying to get access to the constant M_PI (3.14159...). I have imported the math.h header file, but the M_PI constant was still undefined. Through some searching on StackOverflow I have found that I need to add #define…
robintw
  • 27,571
  • 51
  • 138
  • 205
29
votes
1 answer

Can't get rid of "this decimal constant is unsigned only in ISO C90" warning

I'm using the FNV hash as a hashing algorithm on my Hash Table implementation but I'm getting the warning in the question title on this line: unsigned hash = 2166136261; I don't understand why this is happening because when I do…
rfgamaral
  • 16,546
  • 57
  • 163
  • 275
25
votes
3 answers

How standard is the {0} initializer in C89?

In my current project, which uses the MISRA 2004 standard, we use three GCC compilers, versions 3.2.3, 4.4.2 and 5.4.0. We run build checks with the pedantic switch and c89 standard and a load of other restrictions. One of the restrictions is that…
Walkingbeard
  • 590
  • 5
  • 15
25
votes
2 answers

How to compile for a freestanding environment with GCC?

The code I'm working on is supposed to be possible to build for both hosted and freestanding environments, providing private implementations for some stdlib functions for the latter case. Can I reliably test this with just GCC on a normal…
Christoffer
  • 12,712
  • 7
  • 37
  • 53
24
votes
3 answers

Warning: this decimal constant is unsigned only in ISO C90

Piece of code : long rangeVar = 0; rangeVar = atol(p_value); if (rangeVar >= -2147483648 && rangeVar <= 2147483647) On compiling I get: warning: this decimal constant is unsigned only in ISO C90 Thanks in Advance
user1227514
  • 241
  • 1
  • 2
  • 5
24
votes
4 answers

What does (void)var actually do?

Consider the following main(): int main(int argc, char *argv[]) { return (0); } Upon compilation with cc -Wall -Wextra, warnings saying "unused parameter" get generated. When I do not need to use a parameter in a function (for instance in a…
Diti
  • 1,454
  • 3
  • 23
  • 38
23
votes
3 answers

C: convert double to float, preserving decimal point precision

i wanted to convert double to float in C, but wanted to preserve the decimal point exactly as possible without any changes... for example, let's say i have double d = 0.1108; double dd = 639728.170000; double ddd = 345.2345678 now correct…
sdfg
  • 393
  • 2
  • 5
  • 9
22
votes
2 answers

Recursive declaration of function pointer in C

I'd like to declare a function that returns a pointer to a function of the same type. I would like to use it to implement state machines like the one below: typedef event_handler_t (*event_handler_t)(event_t*); // compilation error event_handler_t…
Piotr Czapla
  • 25,734
  • 24
  • 99
  • 122
22
votes
7 answers

A good C equivalent of STL vector?

I've noticed that at several places in our code base we use dynamically expanding arrays, i.e. a base array coupled with an element counter and a "max elements" value. What I want to do is replace these with a common data structure and utility…
Christoffer
  • 12,712
  • 7
  • 37
  • 53
22
votes
3 answers

How to use make and compile as C99?

I'm trying to compile a linux kernel module using a Makefile: obj-m += main.o all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules clean: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean Which gives me: main.c:54:…
djTeller
  • 515
  • 2
  • 5
  • 14
21
votes
3 answers

Typesafe varargs in C with gcc

Many times I want a function to receive a variable number of arguments, terminated by NULL, for instance #define push(stack_t stack, ...) _push(__VARARG__, NULL); func _push(stack_t stack, char *s, ...) { va_list args; va_start(args, s); …
mikebloch
  • 1,577
  • 11
  • 21
1
2
3
42 43