Fog Creek Software
Discussion Board




library compilation problem (c source)

Hi all, It's me again. I apologize for my bad english, it's because I'm french. I'm trying to recompile a fractal generator library  found on
http://users.ox.ac.uk/~linc1040/fractals/source.shtml
My compiler can't autoinitialize these lines
(img_byte) (i.width & 0xFF),            // width low byte
(img_byte) (i.width >> 8),              // width high byte
(img_byte) (i.height &0xFF),            // height low byte
(img_byte) (i.height >> 8),            // height high byte       
with img_byte defined like this
struct img_image {
    struct img_color *pixel;
    int width, height;
};

It claims "Constant expected"
I'm new to c, and I don't understand those lines.

Thanks for helping

Victor
Thursday, February 05, 2004

Sorry I haven't mentioned what the img_color struct is.
struct img_color {
    double r, g, b;
};
And that the compiler claims for those lines
// struct img_color c = {r,g,b};
Which I have changed with those lines (which work)
struct img_color c;
        c.r = r;
        c.g = g;
        c.b = b;
        return c;
What I want to know is how to change the lines mentioned above, in the first post??

Victor
Thursday, February 05, 2004

Sorry, me again, my compiler is Open Watcom the last version, and I don't know c very well, I'm learning with those fractals stuff.

Victor
Thursday, February 05, 2004

http://www.amazon.com/exec/obidos/tg/detail/-/0131103628/qid=1076028073//ref=sr_8_xs_ap_i1_xgl14/103-2899535-2782227?v=glance&s=books&n=507846


Good luck.

.NET Developer
Thursday, February 05, 2004

I haven't downloaded the code, but I can see the problem:

1. I think you will find image_byte is not defined how you say it is in your first post. It can not be, the struct you posted defines img_image, *not* img_byte.

2. Reading the code you posted, it *really* looks like it comes from initializing an array of char's or unsigned char's.  For example a 2 byte interger is being split into 2 bytes (i.width) and then the same again for i.height.  This also fits with the (img_byte) casts, and the commas separating the items.

3. To summarize 1 and 2: (i) img_byte must be a char or unsigned char (99.9% probability), (ii) the initialization is an array of img_bytes, not a struct (99% probability).

4. My guess is you will find something in the code like

img_byte arrayname[number0] =
{
number1, number2, number3,
(img_byte) (i.width & 0xFF),            // width low byte
(img_byte) (i.width >> 8),              // width high byte
(img_byte) (i.height &0xFF),            // height low byte
(img_byte) (i.height >> 8),           
number4, number5, number6
} ;

(where "number" can be any number 0 to 255 or perhaps other similar calculations to the ones giving you problems).  The arrayname may differ, and it may of course have an assumed size (no number 0 just empty [] in which case you have to count the elements for the fix below)

So change the code to read something like

img_byte arrayname[number0] ;
array[0] = number1 ;
array[1] = number2 ;
..etc..
array[whatever] = (img_byte) (i.width & 0xFF) ;
...etc..

If there are a huge number of numbers in the old code and you just have problems with a few specific lines, comment these calculations out and put dummy numbers for them.  The immediately afterwards set up these values (remember first element of array is element 0)

i.e. something like

img_byte arrayname[number0] =
{
number1, number2, number3,
0,
0,
0,
0,
number4, number5, number6
} ;

array[whatever] = (img_byte) (i.width & 0xFF) ;
...etc...



P.S.
int is 32 bits in Win32

if this is Win16 code, int is 16 bits, so it is possible you might have to change some/all ints to shorts (16 bit in Win32). I'd get some advice before making such a drastic step

S.Tanna
Thursday, February 05, 2004

First, as another poster noted, img_byte is defined as

  typedef unsigned char img_byte;  // 8 bits unsigned

Then, I am able to compile it with gcc (mingw) version 3.2.3

What is the exact error message that you get?

Rene

René Nyffenegger
Friday, February 06, 2004

*  Recent Topics

*  Fog Creek Home