Problem With Global Structures

H

Harry

Good Day,


I am writing a code for the H.264 Video codec.I am using VC++
compiler,but programming is in c only.I have grouped the related global
variables under one structure in a header file called global.h.Like
this i have two three structures in global.h.

To initialise the structure members in global.h,I declared structure
variables in c files wherever the structure members are used.

For example
This is one of the structure in global.h

typedef struct
{
int YUV;
int img_height;
int img_width;
int intra_period;
int IntraPeriod;//period of I-frames
int SPPicturePeriodicity; // SP-Picture Periodicity (0=not used)
int BReferencePictures; //Referenced B coded pictures (0=off, 1=on)
int start_frame_no_in_this_IGOP;
int BitDepthLuma;
int BitDepthChroma;
int InterSearch16x16;
int InterSearch16x8;
int InterSearch8x16;
int InterSearch8x8;
int InterSearch8x4;
int InterSearch4x8;
int InterSearch4x4;
int Transform8x8Mode;
int symbolMode;//Symbol mode (Entropy coding method: 0=UVLC, 1=CABAC)
int EnableIPCM;
int NoBframes;//no of b frames to be inserted
int UseHadamard;// Hadamard SymbolModeform (0=not used, 1=used)
int FrameSkip;//no of frames to be skipped
int RDopt;//2 means Fast High Complexity Mode\
}InputParameters;


In the above structure,for example if i want to initialize the
img_width,img_height variables with some value in a c file where it is
used,for example call it encoder.c,I have declared structure variable
like as

InputParameters inputs,*input=&inputs;

Now i can initialize the variable in any of the following ways

inputs.img_width=176; (or) input->img_width=176;
inputs.img_height=144; (or)input->img_height=144;

But i am getting the following error when i comile the c file,encoder.c

c:\documents and settings\hari\desktop\enocoder\encoder.c(4) : error
C2143: syntax error : missing '{' before '.'
c:\documents and settings\hari\desktop\enocoder\encoder.c(4) : error
C2059: syntax error : '.'



Can you suggest any other way for initailsing the structure member
variables direclty with some values.....

Thanks in advance
 
?

=?ISO-8859-1?Q?=22Nils_O=2E_Sel=E5sdal=22?=

Harry said:
Good Day,


I am writing a code for the H.264 Video codec.I am using VC++
compiler,but programming is in c only.I have grouped the related global
variables under one structure in a header file called global.h.Like
this i have two three structures in global.h.

To initialise the structure members in global.h,I declared structure
variables in c files wherever the structure members are used.

For example
This is one of the structure in global.h

typedef struct
{
int YUV;
int img_height;
int img_width;
int intra_period;
int IntraPeriod;//period of I-frames
int SPPicturePeriodicity; // SP-Picture Periodicity (0=not used)
int BReferencePictures; //Referenced B coded pictures (0=off, 1=on)
int start_frame_no_in_this_IGOP;
int BitDepthLuma;
int BitDepthChroma;
int InterSearch16x16;
int InterSearch16x8;
int InterSearch8x16;
int InterSearch8x8;
int InterSearch8x4;
int InterSearch4x8;
int InterSearch4x4;
int Transform8x8Mode;
int symbolMode;//Symbol mode (Entropy coding method: 0=UVLC, 1=CABAC)
int EnableIPCM;
int NoBframes;//no of b frames to be inserted
int UseHadamard;// Hadamard SymbolModeform (0=not used, 1=used)
int FrameSkip;//no of frames to be skipped
int RDopt;//2 means Fast High Complexity Mode\
}InputParameters;


In the above structure,for example if i want to initialize the
img_width,img_height variables with some value in a c file where it is
used,for example call it encoder.c,I have declared structure variable
like as

InputParameters inputs,*input=&inputs;

Now i can initialize the variable in any of the following ways

inputs.img_width=176; (or) input->img_width=176;
inputs.img_height=144; (or)input->img_height=144;
This is assignment not initialization, and needs to be done within a
function body.

If you want to initialize it:
InputParameters inputs = { 1,2,3,4 };

With C99, you can specify which members to initialize:
InputParameters inputs = { .img_width=176,.img_height=144};
 
H

Harry

Nils said:
This is assignment not initialization, and needs to be done within a
function body.

If you want to initialize it:
InputParameters inputs = { 1,2,3,4 };

With C99, you can specify which members to initialize:
InputParameters inputs = { .img_width=176,.img_height=144};


I know that this is the way to assign values to structrure member
variables,but if there are too many variables in the structure we can't
go on like...{2,6,7,........}.......what is wrong with my way of
assigning the initial values to the structure member variables
 
?

=?ISO-8859-1?Q?=22Nils_O=2E_Sel=E5sdal=22?=

Harry said:
I know that this is the way to assign values to structrure member
variables,but if there are too many variables in the structure we can't
go on like...{2,6,7,........}.......what is wrong with my way of
assigning the initial values to the structure member variables

There is nothing wrong with that, but as I said you need to do that
within a function body. It is unclear if your code tries to do that
at file scope - which is not legal. So, put that code in main, or
another function you call pretty quick..


As I also mentioned, provided you have a C99 compiler, you can
specify which members to initialize. I'm not sure this is supported
by Microsoft..
 
H

Harry

Nils said:
There is nothing wrong with that, but as I said you need to do that
within a function body. It is unclear if your code tries to do that
at file scope - which is not legal. So, put that code in main, or
another function you call pretty quick..


As I also mentioned, provided you have a C99 compiler, you can
specify which members to initialize. I'm not sure this is supported
by Microsoft..

Thanks for your help dude
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,701
Latest member
XavierQ83

Latest Threads

Top