Newbie problem with MACROS

S

sieg1974

Hi,

When I try to compile the following program, the compiler tells that
initializer is not a constant in line 14. What's wrong with this code?

Thanks,

Andre

#include <stdio.h>

#define UINT16 unsigned short int

#define ALIGN4( x ) ( ((x)+3) & (~3))

#define TFO_MAX_AMR_PAYLOAD_SIZE 32

UINT16 HSF_PKT_TOTALSIZE(UINT16 payloadLength)
{
return ((UINT16)(400));
}

const int TFO_INGR_SCRATCH_SIZE =
ALIGN4(HSF_PKT_TOTALSIZE(TFO_MAX_AMR_PAYLOAD_SIZE));

void main()
{
printf( "%d\n", TFO_INGR_SCRATCH_SIZE );
}
 
L

Lew Pitcher

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

When I try to compile the following program, the compiler tells that
initializer is not a constant in line 14. What's wrong with this code?

Thanks,

Andre

#include <stdio.h>

#define UINT16 unsigned short int

#define ALIGN4( x ) ( ((x)+3) & (~3))

#define TFO_MAX_AMR_PAYLOAD_SIZE 32

UINT16 HSF_PKT_TOTALSIZE(UINT16 payloadLength)
{
return ((UINT16)(400));
}

const int TFO_INGR_SCRATCH_SIZE =
ALIGN4(HSF_PKT_TOTALSIZE(TFO_MAX_AMR_PAYLOAD_SIZE));

The initializer of TFO_INGR_SCRATCH_SIZE requires a function call to
HDF_PKT_TOTALSIZE() in order to obtain it's value. This means that the
initializer is not a constant (it's the return value of a function
call), and that's illegal.
void main()
{
printf( "%d\n", TFO_INGR_SCRATCH_SIZE );
}


- --

Lew Pitcher, IT Consultant, Enterprise Data Systems
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed here are my own, not my employer's)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)

iD8DBQFBYsBTagVFX4UWr64RArN/AKCsWhz9oof5OxkRqVuDtkL12S7CTACg05sS
WwvmhF9YfunN6e+mOVNlDOs=
=o/TC
-----END PGP SIGNATURE-----
 
P

Pedro Graca

sieg1974 said:
When I try to compile the following program, the compiler tells that
initializer is not a constant in line 14. What's wrong with this code?

#include <stdio.h>

#define UINT16 unsigned short int

#define ALIGN4( x ) ( ((x)+3) & (~3))

#define TFO_MAX_AMR_PAYLOAD_SIZE 32

UINT16 HSF_PKT_TOTALSIZE(UINT16 payloadLength)
{
return ((UINT16)(400));
}

const int TFO_INGR_SCRATCH_SIZE =
ALIGN4(HSF_PKT_TOTALSIZE(TFO_MAX_AMR_PAYLOAD_SIZE));
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
You cannot initialize a global variable (be it constant or not) using
a function call.
void main()

the correct return type of main() is int.
 
S

sieg1974

Pedro Graca said:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
You cannot initialize a global variable (be it constant or not) using
a function call.


the correct return type of main() is int.

Is it possibel to correct it just modifying the follwong line of code,
and let the others untouched? If so, do you guys have any suggestions?

const int TFO_INGR_SCRATCH_SIZE =
ALIGN4(HSF_PKT_TOTALSIZE(TFO_MAX_AMR_PAYLOAD_SIZE));

Thanks,

Andre
 
P

Pedro Graca

sieg1974 said:
Pedro Graca said:
sieg1974 wrote: [snip]
#define TFO_MAX_AMR_PAYLOAD_SIZE 32

UINT16 HSF_PKT_TOTALSIZE(UINT16 payloadLength)
{
return ((UINT16)(400));
}

const int TFO_INGR_SCRATCH_SIZE =
ALIGN4(HSF_PKT_TOTALSIZE(TFO_MAX_AMR_PAYLOAD_SIZE));
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
You cannot initialize a global variable (be it constant or not) using
a function call.

Is it possibel to correct it just modifying the follwong line of code,
and let the others untouched? If so, do you guys have any suggestions?

const int TFO_INGR_SCRATCH_SIZE =
ALIGN4(HSF_PKT_TOTALSIZE(TFO_MAX_AMR_PAYLOAD_SIZE));


Try:

const int TFO_INGR_SCRATCH_SIZE = ALIGN4( ((UINT16)(400)) );
 

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,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top