Help Required - compilation error.

david.hagood@gmail.com david.hagood@gmail.com
Thu Aug 11 16:26:00 GMT 2011


> Hi,
>
> I used GCC 2.7.2.3 in the past to compile the following code:
> class sample
> {
> private:
> unsigned char wk_tmp[20000 - ((int)(long)&(((DATASTRUCTURE*)0)->mydata))];
>
> };

Your code is broken.

You REALLY want to use a smarter type here:

#include <vector>
class sample
{
   private:
     std::vector<unsigned char> wk_temp;
   public:
     sample();
};

sample::sample()
:wk_temp((int)(long)&(((DATASTRUCTURE*)0)->mydata)))
{
}

Using a vector will let the language handle the allocation of the space,
check for overflows, and so on.

(now, the wisdom of what you are using this for - why the allocation type,
etc. are another issue you may want to think about, but you didn't give us
enough information to help you there.)

Bottom line: you REALLY shouldn't be using dumb types like C arrays or
pointers in C++ if you can avoid it.




More information about the Gcc-help mailing list