What exactly is -fno-builtin doing here?

From man gcc -fno-builtin -fno-builtin-function Don’t recognize built-in functions that do not begin with __builtin_ as prefix. GCC normally generates special code to handle certain built-in functions more efficiently; for instance, calls to “alloca” may become single instructions which adjust the stack directly, and calls to “memcpy” may become inline copy loops. The resulting code … Read more

Does C have a string type? [closed]

C does not and never has had a native string type. By convention, the language uses arrays of char terminated with a null char, i.e., with ‘\0′. Functions and macros in the language’s standard libraries provide support for the null-terminated character arrays, e.g., strlen iterates over an array of char until it encounters a ‘\0’ … Read more

Segmentation Fault in strcpy()

Your typedef defines Truck as a struct struck *, i.e. a pointer. So it’s size will be 4 or 8 depending on the architecture and not the size of the struct Use sizeof(*Truck) to get the actual size of the struct. You also need to allocate memory for the characters. The easiest way would be … Read more

strcpy vs strdup

strcpy(ptr2, ptr1) is equivalent to while(*ptr2++ = *ptr1++) where as strdup is equivalent to ptr2 = malloc(strlen(ptr1)+1); strcpy(ptr2,ptr1); (memcpy version might be more efficient) So if you want the string which you have copied to be used in another function (as it is created in heap section) you can use strdup, else strcpy is enough.

strcpy() return value

as Evan pointed out, it is possible to do something like char* s = strcpy(malloc(10), “test”); e.g. assign malloc()ed memory a value, without using helper variable. (this example isn’t the best one, it will crash on out of memory conditions, but the idea is obvious)

C – why is strcpy() necessary

Arrays in C are non-assignable and non-copy-initializable. That’s just how arrays are in C. Historically, in value context (on the RHS of assignment) arrays decay to pointers, which is what formally prevents assignment and copy-initialization. This applies to all arrays, not only to char arrays. C language inherits this arrays behavior from its predecessors – … Read more