Do all the things like ++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatarSign Up
IllSlapU14011238dYes. Because these are pointers, the compiler will take care of the conversion, which could fail and lead to bigger problems, if the structs arent the same size. Like these two.
IllSlapU14011238dBtw. Having a structure with only one variable in it is an awful habit. why not declare it directly ?
jaread299238dIt should work, probably - the memory layout of Model and ModelA (up to the first 4 or 8 bytes (the size of a pointer)) should be the same. A good idea? probably not.
lo98be782237dWell, there shouldn't be any problem
Unless you try to use "value" before re-initialization
And it could give bigger problems if ma was an array since ma is a pointer and so is m. ma+1 has a size and m a different one which means overwriting stuff over and over
It really isn't the best idea unless you really know what you're doing
I wouldn't feel comfortable with a bomb like that
gblues507237d"legal" is very loosely defined in C. This technique is basically a poor man's interface. The important thing is that the members have to be in the same order and the same types.
sixteenbitt28237dThat's legalish (hey, I guess it works), but I think that falls into the category of "Don't ever do this in production." I'm not positive if that falls into the category of undefined behavior, but I wouldn't be shocked if cranking the optimizations up on the compiler broke that
lo98be782237dI just realized I didn't answer your question @cpp0xc0ffeeee
It's perfectly legal, meaning it compiles correctly
It won't work unless it's handled veery carefully
And it's also unlikely to crash, meaning it will probably disrupt a shit ton of data before being corrected
Avoid or refactor it, that's what I'd do
I just answer in the rants where I am able to answer.