Re: declaration meaning



Darko schrieb:
If this works, then it's a work of art. :) Of course - if one was to
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?

work of art? I'd say that's a landmine.

- 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>
.



Relevant Pages

  • Re: declaration meaning
    ... declare it as a variable, it would get a compiler error. ... get a name we later hold for when referring to allocated memory. ... The technique described in the previous article is the "struct hack", ...
    (comp.lang.c)
  • Re: Option Explicit
    ... but I thought that Access reserves a place in the memory only when you ... Explicit and declare your variables. ...
    (microsoft.public.access.formscoding)
  • Re: local static variables on the heap?
    ... > Hi, if I declare a local variable with the 'static' keyword, where does ... outside of functions have a life time of the program. ... Another type of memory allocation is for dynamic ... static local variables may live in the same area ...
    (alt.comp.lang.learn.c-cpp)
  • Re: When to kill an object
    ... "locals" and take more care with cross app code as you suggest. ... Are you able to point me towards a good background on memory management? ... > The one exception to this is if I declare objects which are links to other ... > programs such as ADO record sets or instantiations of other programs like ...
    (microsoft.public.excel.programming)
  • Re: scratch memory
    ... [quotin myself] ... The wording of the original poster could be read as suggesting that the ... original poster was unaware that static'd memory continues to hang ... In such a scenario does it make sense to declare a memory in global or ...
    (comp.lang.c)