Do all the things like ++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatarSign Up
Skerp13765317dYes. 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.
Skerp13765317dBtw. Having a structure with only one variable in it is an awful habit. why not declare it directly ?
jaread297317dIt 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.
cpp0xc0ffeeee438317d@Lahsen2016 it's a example, actually it has more members.
lo98be782317dWell, 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
gblues509317d"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.
sixteenbitt28317dThat'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
lo98be782316dI 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
-ANGRY-CLIENT-9974316d@Lahsen2016 do you explicitly search for "pointer" rants xD
I just answer in the rants where I am able to answer.
Your Job Suck?
Take a quick quiz from Triplebyte to skip the job search hassles and jump to final interviews at hot tech firms
Get a Better Job