473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

macro for compile time allocation

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

Nov 14 '05 #1
2 1137
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
Nov 14 '05 #2
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
Nov 14 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
17
by: newbiecpp | last post by:
I have hard time to understand run-time environment. Let assume that I have a program that has a simple variable alpha. When this variable is statically allocated, the compiler can use the...
5
by: Carmine Cairo | last post by:
Hi, I'm working on a project and today I've note a little problem during the compile fase. Here a little piece of code: // 1st version welldone = 0; size = p->getSize(); backbone = new...
7
by: Jim Cook | last post by:
We have a macro which takes various index constants as an argument and offsets into an array. The macro can be an Lvalue or Rvalue. The index is not zero based. I would like a compile time error...
9
by: userblue | last post by:
Hi Does anyone know if there is a way to define what is effectively a single globally visible, enumerated list whilst actually defining the entries across several different modules? or somehow do...
0
by: He Shiming | last post by:
Hi All, In my COM (component object model) server DLL I created, there are these methods that require buffer allocation. They look like this: class CComClass : public IClass { // just for...
11
by: Kavya | last post by:
offsetof(T,m) (size_t)&(((T*)0)->m) Why do we always start from 0 in this macro to access the offset of structure or union. Does standard guarantees that structure and union reside at address 0?...
8
by: Peithon | last post by:
Hi, I'm initialising unit test structures using a macro as follows: #define UTMACRO(x) UT##x typedef struct { char * key; char * arr;
27
by: CodeMonk3y | last post by:
gotta question on sizeof keyword does the sizeof keyword calcuates the size at compile time or run time ?? -- Posted on news://freenews.netfront.net - Complaints to news@netfront.net --
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.