![]() Now, although I am assigning incompatible pointer types, and the C spec says behavior is undefined, does GCC or other compilers make any design claim on how this case is handled? I can almost swear that this OUGHT TO WORK due to how struct memory is laid out, but I cannot find the proof. ![]() The code works as long as I have the "struct MyIf myinterface" to be the first member of the struct, which is by design (I like to shoot myself in the foot) You do not need to cast the pointer explicitly. that the name of the union set is v, we simply update us pointer to point to v. When I compile, as I expect, I get for assigning the pointers in newObj1(), warning: assignment from incompatible pointer type In ISO C, a pointer to void can be assigned to a pointer of any other type. other requests that are not compatible, and accept the request that has. Struct MyIf* myIf = (struct MyIf*) newObj1() Struct Obj1* obj = malloc(sizeof(struct Obj1)) 'ies' is not a single character, it is a string - an array of characters that decays to a pointer to the first character. * Functions here are "equivalent" to methods on the Obj1 struct */ dtype: u, length: u, pointer: 0x08xn msgstr -: vms-alpha.c:7075 +. read readproc, warning: (near initialization for ‘procfops. * The object, can be in different header */ glinkPLTresolve save of r2 is incompatible with code. warning: initialization from incompatible pointer type enabled by default. I have a working C code when compiled using GCC, but I am trying to find out if the code works because of pure luck or because GCC handles this code as I expect by design. It would give incompatible types: you would violate the strict aliasing rule and there might also be alignment issues. ![]()
0 Comments
Leave a Reply. |