Define and array initialisation

M

Michael

Hi all,

I have got a simple question about the
#define command: Can I use it for array
initialisation?

E.g.

#define ARRAYINIT { {0, 1}, {2,3} }

....
int main ( void )
{
int somestuff[][] = ARRAYINIT;
...
}

Thanks,
Michael
 
A

Alex Fraser

Michael said:
I have got a simple question about the
#define command: Can I use it for array
initialisation?

E.g.

#define ARRAYINIT { {0, 1}, {2,3} }

...
int main ( void )
{
int somestuff[][] = ARRAYINIT;
...
}

Yep. After the preprocessing phase the source will read:

....
int main ( void )
{
int somestuff[][] = { {0, 1}, {2,3} };
...
}

Alex
 
M

Michael

Alex said:
Yep. After the preprocessing phase the source will read:

...
int main ( void )
{
int somestuff[][] = { {0, 1}, {2,3} };
...
}

Alex

Hi Alex,

thanks for the quick response.
Regards
Michael
 
E

Emmanuel Delahaye

Alex Fraser said:
Yep. After the preprocessing phase the source will read:

...
int main ( void )
{
int somestuff[][] = { {0, 1}, {2,3} };
...
}

That is not C.

int somestuff[][2] = { {0, 1}, {2,3} };
 
E

Emmanuel Delahaye

In 'comp.lang.c' said:
I have got a simple question about the
#define command: Can I use it for array
initialisation?

#define ARRAYINIT { {0, 1}, {2,3} }
...
int main ( void )
{
int somestuff[][] = ARRAYINIT;
...
}

Yes, but the dimensions of the array should be added

int somestuff[2][2] = ARRAYINIT;

only the lefmost dimension can be ommited :

int somestuff[][2] = ARRAYINIT;
 
M

Michael

Yes, but the dimensions of the array should be added
int somestuff[2][2] = ARRAYINIT;

only the lefmost dimension can be ommited :

int somestuff[][2] = ARRAYINIT;

Hi,

yeah, my compiler already complaint about that. But I got
an other question. My compiler complains about an Yx1 array
like:

int somestuff[6][1] = { {1}, {1}, {1}, {1}, {1}, {1} };

I know, I can do it with one dimension, but due the programm
structure I would prefer to realize the above array.
Is the a chance?
Thanks,
Michael
 
E

Emmanuel Delahaye

In 'comp.lang.c' said:
My compiler complains about an Yx1 array
like:

int somestuff[6][1] = { {1}, {1}, {1}, {1}, {1}, {1} };

I know, I can do it with one dimension, but due the programm
structure I would prefer to realize the above array.

or

int somestuff[][1] = { {1}, {1}, {1}, {1}, {1}, {1} };

Well, I don't see what does your compiler complain about. Sounds good to me.
Must be something else.
 
M

Michael

Emmanuel Delahaye wrote:
[...]
Well, I don't see what does your compiler complain about. Sounds good to me.
Must be something else.
Exactly. You are right it was something else.
Thanks again ....
Michael
 

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

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top