gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > coding using const structs

#36449 - gbawiz - Sun Feb 20, 2005 8:26 pm

I am a bit stuck with the following messages:
when attempting compilation in windows I get:

Code:
warning C4090: 'initializing' : different 'const' qualifiers

When in GCC compiler I get:

Code:
warning: initialization discards qualifiers from pointer target type
[/img]

I am actually trying to include a file which has something like the following:

Code:
const sampletype sampleinfo[]={
{ 5160, 0, 64, 0, 1, sample_0 },
{ 3584, 0, 64, 0, 1, sample_1 },
etc.................


where sampletype is a struct which has been previously defined
Anyone help?
Thanks

#36450 - poslundc - Sun Feb 20, 2005 8:42 pm

Odds are you are referencing const data when you refer to sample_0, sample_1, etc. but the data type within your struct is non-const.

Dan.

#36451 - tepples - Sun Feb 20, 2005 9:02 pm

Show the typedef and or struct statements that define the type sampletype and we'll show you how to fix this the right way.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#36457 - gbawiz - Mon Feb 21, 2005 11:45 am

tepples wrote:
Show the typedef and or struct statements that define the type sampletype and we'll show you how to fix this the right way.


Code:
typedef struct sample_info_layout
{
   unsigned int length;
   unsigned char finetune;
   unsigned char volume;
   unsigned int rpt_offset;
   unsigned int rpt_length;
   unsigned char *sample_data;
}sampletype;


seems to work when I place 'const' in front of the bottom definition 'unsigned char *sample_data'
However this is when creating an output from a mod converter file only.

If I try adding this when filling the struct initially with the data then there is an error.

I am attempting a mod file converter based on Deku's method

#36463 - tepples - Mon Feb 21, 2005 5:29 pm

gbawiz wrote:
tepples wrote:
Show the typedef and or struct statements that define the type sampletype and we'll show you how to fix this the right way.


Code:
typedef struct sample_info_layout
{
   unsigned int length;
   unsigned char finetune;
   unsigned char volume;
   unsigned int rpt_offset;
   unsigned int rpt_length;
   unsigned char *sample_data;
}sampletype;


seems to work when I place 'const' in front of the bottom definition 'unsigned char *sample_data'

That's what I would have suggested.

Quote:
However this is when creating an output from a mod converter file only.

If I try adding this when filling the struct initially with the data then there is an error.

Which error is this? And how have you defined sample_0 and sample_1?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#36465 - gbawiz - Mon Feb 21, 2005 8:46 pm

I create an empty mod file struct and copy the modfile into the appropriate locations.

The error appears when I state that part of the struct is a const when it has not yet been defined or filled with data.
However once I write the struct definitions to the output.h file to include in my GBA programs then thats where the const is needed. Because the data which has now been stored in the structs have all to be stored into the output.h file also (using fprintf).

This whole subject of saving struct data in this way is new to me and Im having a bit of trouble, im getting the following:
Code:
modconverted.h:9083: warning: initialization makes integer from pointer without a cast


Code:
const modtype modtable[]= {

sampleinfo,
31,
127,
pattern_order,
modpatterntable
 };


they have all been defined before as:

Code:
const unsigned char *modpatterntable[]={
pattern_0, pattern_1, pattern_2, pattern_3, pattern_4, pattern_5, pattern_6, pattern_7, pattern_8, pattern_9, pattern_10, pattern_11, pattern_12, pattern_13, pattern_14, pattern_15, pattern_16, pattern_17, pattern_18, pattern_19,
};


Code:
const sampletype sampleinfo[]={
{ 5160, 0, 64, 0, 1, sample_0 },
{ 3584, 0, 64, 0, 1, sample_1 },
etc........................
};



Code:
const unsigned char sample_0[]={
0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,254,
252,249,246,243,240,236,233,232,239,244,241,255,0,248,255,7,
etc.............
};

same for each of the samples available

Code:
const unsigned char pattern_order[]={
2, 0, 0, 1, 1, 3, 4, 16, 5, 6, 7, 8, 5, 6, 7, 8, 17, 18, 13, 14, 13, 14, 9, 10, 11, 12, 5, 6, 7, 8, 19,
};


Sorry for the length
Thanks

#36468 - sajiimori - Mon Feb 21, 2005 10:29 pm

Which initialization is giving the error (at line 9083)? How is modtype defined? How are pattern_* defined?

#36470 - gbawiz - Mon Feb 21, 2005 11:28 pm

Found problem, forgot to define types in main mod header :)
Thanks