Re: declaration meaning
- From: michi <spam@xxxxxxxxxxx>
- Date: Sun, 07 May 2006 20:23:57 +0200
Darko schrieb:
If this works, then it's a work of art. :) Of course - if one was towork of art? I'd say that's a landmine.
declare it as a variable, it would get a compiler error. However,
declaring it in a structure doesn't do the allocating itself, we just
get a name we later hold for when referring to (m)allocated memory.
Genialno. :) So, it actually works only for structs?
- Anyone unsuspiciously using a memcpy(pX,pFoo,sizeof(*pFoo)) will get surprising results.
- Using malloc, one must take into account that the storage for the first element is covered by sizeof(stuct message) while the rest is not.
- for copying you should at least provide a size_t len member to determine the "extra" space.
- it makes your code wide open for heap-overflow attacks and code injection exploits.
- It's impossible to have these objects on the stack, even if the compiler permits it.
- Consider using #pragma pack(1) struct ... #pragma pack()
this will provide you at least with defined memory-layouts you are using reinterpret-casts to the "char" data, even if packing was modified from somewhere else. (cc options, foreign headers)
I'd suggest not to use this construct even if it's convenient.
<flame mode="plenty">
variable sized array are pure evil
</flame>
.
- Follow-Ups:
- Re: declaration meaning
- From: Keith Thompson
- Re: declaration meaning
- References:
- declaration meaning
- From: krishna
- Re: declaration meaning
- From: Roberto Waltman
- Re: declaration meaning
- From: Darko
- declaration meaning
- Prev by Date: Re: printf headache
- Next by Date: Re: How to sscanf return integer only
- Previous by thread: Re: declaration meaning
- Next by thread: Re: declaration meaning
- Index(es):
Relevant Pages
|