Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > macro for compile time allocation

Reply
Thread Tools

macro for compile time allocation

 
 
moose
Guest
Posts: n/a
 
      05-18-2005
Can someone explain why the following will not work,

#define MYSTRUCT(name,size) struct my_struct_ ## name {
unsigned char name ## _array[ size ] ;
} ;

MYSTRUCT( foo , 10 )

The error is because the size doesnt appear to be known at compile time
to create the array but why not ? this is a macro not a function.

Any comments welcome

 
Reply With Quote
 
 
 
 
pete
Guest
Posts: n/a
 
      05-18-2005
moose wrote:
>
> Can someone explain why the following will not work,
>
> #define MYSTRUCT(name,size) struct my_struct_ ## name {
> unsigned char name ## _array[ size ] ;
> } ;


You need two backslashes.

#define MYSTRUCT(name,size) struct my_struct_ ## name {\
unsigned char name ## _array[ size ] ;\
} ;

--
pete
 
Reply With Quote
 
 
 
 
CBFalconer
Guest
Posts: n/a
 
      05-18-2005
pete wrote:
> moose wrote:
>>
>> Can someone explain why the following will not work,
>>
>> #define MYSTRUCT(name,size) struct my_struct_ ## name {
>> unsigned char name ## _array[ size ] ;
>> } ;

>
> You need two backslashes.
>
> #define MYSTRUCT(name,size) struct my_struct_ ## name {\
> unsigned char name ## _array[ size ] ;\
> } ;


You might tell him why. #defines have to be complete on one line.
To write them on multiple lines you have to escape the line
endings, which means an escape char (the \) at the end of each
continued line. Nothing follows the escape except the eoln marker.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
An idea for heap allocation at near stack allocation speed Bjarke Hammersholt Roune C++ 14 03-06-2011 08:07 AM
computation at compile time i.e. compile time functions usingtemplates Carter C++ 2 03-04-2009 06:43 PM
cant compile on linux system.cant compile on cant compile onlinux system. Nagaraj C++ 1 03-01-2007 11:18 AM
static memory allocation versus dynamic memory allocation Ken C Programming 24 11-30-2006 12:37 AM
What is the difference between dynamic memory allocation,and stack allocation ? chris C++ 6 10-28-2005 05:27 AM



Advertisments