Newsgroup: it.comp.lang.c++
Titolo: errori di compilazione

Ho trovato questo loader delle immagini tga, ma non riesco a compilarlo con
il microsoft visual c++ 6.0
riporto il codice:
Ho commentato gli errori che trova il compilatore: li ho scritti a lettere
maiuscole e si riferiscono alla linea di codice sottostante.
/****************                cone3dtga.h
**************************/
#ifndef __CONE3D_TGA_H__
#define __CONE3D_TGA_H__
class Cone3DTGA
{
  public:
  Cone3DTGA() {};
  ~Cone3DTGA() {};
  int LoadTGA(char *filename);    // TGA loader
  unsigned int bpp;
  unsigned int width;
  unsigned int height;
  unsigned int texID;
  GLubyte *imageData;
};
#endif
/********************  cone3dtga.cpp
***************************/
int Cone3DTGA::LoadTGA(char *filename)
{
  GLubyte TGAcomment[1];                         // Nr. of bytes used for
the comment
  GLubyte TGAheader[11]={0,2,0,0,0,0,0,0,0,0,0}; // Uncompressed TGA Header
  GLubyte TGAcompare[11];                        // Used To Compare TGA
Header
  GLubyte header[6];                             // First 6 Useful Bytes
From The Header
  GLuint  bytesPerPixel;                         // Holds Number Of Bytes
Per Pixel Used In The TGA File
  GLuint  imageSize;                             // Used To Store The Image
Size When Setting Aside Ram
  GLuint  temp;                                  // Temporary Variable
  GLenum  type=GL_RGBA;                          // Set The Default GL Mode
To RBGA (32 BPP)
  long  i;
  FILE *file = fopen(filename, "rb");            // Open The TGA File
  if(file==NULL ||                               // Does File Even Exist?
     fread(TGAcomment,1,sizeof(TGAcomment),file)!=sizeof(TGAcomment) || //
Try to read the comment byte
     fread(TGAcompare,1,sizeof(TGAcompare),file)!=sizeof(TGAcompare) || //
Are There 12 Bytes To Read?
     memcmp(TGAheader,TGAcompare,sizeof(TGAheader))!=0 || // Does The Header
Match What We Want?
     fread(header,1,sizeof(header),file)!=sizeof(header)) // If So Read Next
6 Header Bytes
  {
    fclose(file);                                // If Anything Failed,
Close The File
    return 0;                                    // Return False
  }
/*   !!!!!!!!IL PRIMO ERRORE DI COMPILAZIONE!!!!!!! :    expected constant
expression   */
/*   !!!!!!!!IL SECONDO ERRORE DI COMPILAZIONE!!!!!!! :  cannot allocate an
array of constant size 0  */
/*   !!!!!!!!IL TERZO ERRORE DI COMPILAZIONE!!!!!!! :  'comment' : unknown
size  */
  char comment[TGAcomment[0]];                   // If the tga image has a
comment then read it
/*   !!!!!!!!IL QUARTO ERRORE DI COMPILAZIONE!!!!!!! :  illegal sizeof
operand  */
if(TGAcomment[0] != 0)
    fread(comment, 1, sizeof(comment), file);
  width  = header[1] * 256 + header[0];          // Determine The TGA Width
(highbyte*256+lowbyte)
  height = header[3] * 256 + header[2];          // Determine The TGA Height
(highbyte*256+lowbyte)
  if(width <=0  ||                               // Is The Width Less Than
Or Equal To Zero
     height <=0 ||                               // Is The Height Less Than
Or Equal To Zero
     (header[4]!=24 && header[4]!=32))           // Is The TGA 24 or 32 Bit?
  {
    fclose(file);                                // If Anything Failed,
Close The File
    return 0;                                    // Return False
  }
  bpp  = header[4];                              // Grab The TGA's Bits Per
Pixel (24 or 32)
  bytesPerPixel = bpp/8;                         // Divide By 8 To Get The
Bytes Per Pixel
  imageSize     = width*height*bytesPerPixel;    // Calculate The Memory
Required For The TGA Data
  imageData=(GLubyte *)malloc(imageSize);        // Reserve Memory To Hold
The TGA Data
  if(imageData==NULL ||                          // Does The Storage Memory
Exist?
     fread(imageData, 1, imageSize, file)!=imageSize) // Does The Image Size
Match The Memory Reserved?
  {
    if(imageData!=NULL)                          // Was Image Data Loaded
      free(imageData);                           // If So, Release The Image
Data
    fclose(file);                                // Close The File
    return 0;                                    // Return False
  }
  for(i=0; i<(long)imageSize; i+=bytesPerPixel)  // Loop Through The Image
Data
  {                                              // Swaps The 1st And 3rd
Bytes ('R'ed and 'B'lue)
    temp=imageData[i];                           // Temporarily Store The
Value At Image Data 'i'
    imageData[i] = imageData[i + 2];             // Set The 1st Byte To The
Value Of The 3rd Byte
    imageData[i + 2] = temp;                     // Set The 3rd Byte To The
Value In 'temp' (1st Byte Value)
  }
  fclose (file);                                 // Close The File
  // Build A Texture From The Data
  glGenTextures(1, &texID);             // Generate OpenGL texture IDs
  glBindTexture(GL_TEXTURE_2D, texID);  // Bind Our Texture
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //
Linear Filtered
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); //
Linear Filtered
  if (bpp==24)                                   // Was The TGA 24 Bits
  {
    type=GL_RGB;                                 // If So Set The 'type' To
GL_RGB
  }
  glTexImage2D(GL_TEXTURE_2D, 0, type, width, height, 0, type,
GL_UNSIGNED_BYTE, imageData);
  return 1;                                      // Texture Building Went
Ok, Return True
}
Grazie .
Ale.

 operand  */
Come dice il primo messaggio la dimensione di un array deve essere
definita tramite una costante di compilazione ed un valore memorizzato
in un array non lo e'.
Ciao,
Nicola