Re: Fwd: Re: [AD] [AL] Problems with dat2c

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Wednesday 09 October 2002 07:33, Christer Sandberg wrote:
> Well, the orignal code of 'do_conversion', which is the
> voilating function, allocates strlen(prefix)+5
> for the case mentioned, and concatenates
> strlen(prefix)"_""data" which requires one byte more
> including eos. The obvious change would maybe be to
[snip]

OK, I see this now.

[snip]
> Yes. If a compiler don't support flexible array members this
> simply means that you can't expect it to handle flexible array
> members...

This really needs to be investigated more. Zero size arrays are evil. 
I'm sorry, but I'm quite short on time this week so I haven't sat and 
studied your code. My idea to fix this problem would be this:

/* for each object with a zero-sized array; in this example, we are 
   using FONT_GLYPH { int w, h; char data[0]; }
struct _anonymous_FONT_GLYPH_n {
  int w, h;
  char data[<number of bytes for this object goes here>];
}
struct _anonymous_FONT_GLYPH_n some_object = {
  8, 8,
  "fontdata"
};

/* and then in the header file: */
extern FONT_GLYPH some_object;


This means that compiling the dat2c-generated source file will generate 
warnings, but otherwise we should be alright. It also depends on the C 
compiler not changing the offsets of members within structures - this 
is an assumption, but it should hold.

I believe you are suggesting something similar, sorry if I stole your 
idea :-)

> ??
> Can you give single example of what you can't do using
> 'p' but you can by using 'global'?
> static int local;
> int *p=&local;
> int global;

Yep. You can't declare a global variable like this:
int* some_global_ptr = p;

but you can like this:
int* some_global_ptr = &global;

This is a useful property because Allegro passes objects around by 
reference (ie. pointers) rather than value; therefore, it is possible 
to use dat2c objects *at compile time* (for instance, to initialise a 
DIALOG[] array with bitmaps, etc).

Bye for now,
- -- 
Laurence Withers,  lwithers@xxxxxxxxxx
(GnuPG 04A646EA) http://www.lwithers.demon.co.uk/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.0 (GNU/Linux)

iD8DBQE9pD59UdhclgSmRuoRAo4qAJ4v3MIYyshecB4RKJBCleNmWUmn2QCfcgi1
aYf6QeTdwty38y/0ARcHkKw=
=Vodt
-----END PGP SIGNATURE-----



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/