FAQ Database Discussion Community

Understanding an unexpected result due to an unmatched 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...

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

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 it possible to test for two new line characters in a row?

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”

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?...

Why do you get different values for integer division in 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?...

Is post-increment operator guaranteed to run instantly?

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?...

Buffer of function pointers?

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?

Initialize an Array Literal Without a Size

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...

Undeclared Identifier although it is declared

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...

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

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...

Segfault when accessing a structure's member

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,...

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

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...