top | item 43915723

(no title)

jklowden | 9 months ago

What drugs were they on? Why on earth is there any distinction between variables allocated statically, on the stack, or on the heap? I allocate a struct, copy data to it, and those data have no Effective Type? Because I started with malloc? Give me a break.

The point of the type system is to define types. It’s not to make the compiler’s job easier, or to give standards committees clouds to build their castles on. No amount of words will justify this misbegotten misinvention.

discuss

order

gizmo686|9 months ago

> If a value is stored into an object having no declared type through an lvalue having a type that is not a character type, then the type of the lvalue becomes the effective type of the object for that access and for subsequent accesses that do not modify the stored value

As I read it, this means that

  struct foo *x = malloc(sizeof(*x))
Will have an effective type of "struct foo*", which seems like what you would expect.

eddd-ddde|9 months ago

But if then you write to that memory through a int pointer the effective type is int. Unlike if you would have allocated the struct in the stack.