Re: Help Required - compilation error.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux