FAQ Database Discussion Community


Initialize an Array Literal Without a Size

c,c89
I'm curious about the following expression: int ints[] = { 1, 2, 3 }; This seems to compile fine even in c89 land with clang. Is there documentation about this? I can't seem to figure out the correct terminology to use when searching for it (and I'd rather not go...

Buffer of function pointers?

c,function,pointers,c89
I know it may sound sci-fi but I truly want to call a function x times, by using an array of function pointers to it and without involving a loop or anything that may slow down the target program. Is that possible and if yes, how exactly?

Understanding an unexpected result due to an unmatched prototype (C89)

c,prototype,c89
I have a program goo.c void foo(double); #include <stdio.h> void foo(int x){ printf ("in foo.c:: x= %d\n",x); } which is called by foo.c int main(){ double x=3.0; foo(x); } I compile and run gcc foo.c goo.c ./a.out Guess what? I get "x= 1" as result. Then I find the signature...

Is it possible to test for two new line characters in a row?

c,newline,c89
I'm trying to validate lines in a file with actual content in them, and exiting on cases where there are two empty lines in a row. Can this be done? This code results in fgetc() not catching the double carriage returns/new lines. Code is a snippet from a C89 project,...

The meaning of β€œEiC”

c++,c,interpreter,c89
It appears that I am unable to find what "EiC" stands for. It has been used as an interpreter, semantic front end IDE similar to "Clang", but a little bit older. What is the meaning of it and why can I not find any reference to it?...

Is following statement valid in ANSI C? Is it valid at all?

c,language-lawyer,c89,sequence-points
During my preparation to exam on ANSI C I have encountered the following question - Is following statement valid? If not, please make required changes to make it valid. The original statement is: test(i++,i++); it isn't valid because the behaviour is undefined according to K&R p202 The order of evaluation...

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

c,language-lawyer,c89
Consider following basic example: #include <stdio.h> 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 implementation-defined and definitely no UB here (with comments of Keith Thompson, that looks contradictory). The...

Undeclared Identifier although it is declared

c,identifier,c89
for a program in which I try to create a file and later write into it, I have written the following: int main(){ ... .... (some code) .... char DataBuffer[] = "This is the test file"; ... ... } I get the error "DataBuffer: undeclared identifier" . I am using...

Segfault when accessing a structure's member

c,pointers,segmentation-fault,gdb,c89
I'm confronted to a strange problem, my program has a segfault when i try to access a structure member but my structure's address is not NULL and I've never freed this structure. The structure's address is something like "0x8000000000" or "0x2000000000". Here is gdb's bt : Program received signal SIGSEGV,...

use char* to compare with a value on string [duplicate]

c,c89
This question already has an answer here: How do I properly compare strings in C? 3 answers Hi I use the function strtok to split an array as follows: char str[] ="one11;one2"; char* pch; pch = strtok (str,";"); while (pch != NULL) pch = strtok(NULL, ";"); Now I need...

Is post-increment operator guaranteed to run instantly?

c,c89,post-increment,ansi-c
Let's say I have the following code: int i = 0; func(i++, i++); The increment is happening right after returning the value? Is it guaranteed that the first argument will be 0, and the second argument will be 1?...

Why do you get different values for integer division in C89?

c,c89
For example, suppose you have these variables: int i = 9; int j = 7; Depending on the implementation, the value of, (-i)/j, could be either –1 or –2. How is it possible to get these two different results?...