473,385 Members | 1,912 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,385 software developers and data experts.

Define and array initialisation

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

Nov 14 '05 #1
7 38527
"Michael" <mi****@gmx.net> wrote in message
news:cc**********@rzcomm2.rz.tu-bs.de...
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
Nov 14 '05 #2
Alex Fraser wrote:
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

Nov 14 '05 #3
In 'comp.lang.c', "Alex Fraser" <me@privacy.net> wrote:
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} };

--
-ed- get my email here: http://marreduspam.com/ad672570
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-reference: http://www.dinkumware.com/manuals/reader.aspx?lib=c99
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
Nov 14 '05 #4
In 'comp.lang.c', Michael <mi****@gmx.net> wrote:
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;

--
-ed- get my email here: http://marreduspam.com/ad672570
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-reference: http://www.dinkumware.com/manuals/reader.aspx?lib=c99
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
Nov 14 '05 #5
> 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

Nov 14 '05 #6
In 'comp.lang.c', Michael <mi****@gmx.net> wrote:
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.

--
-ed- get my email here: http://marreduspam.com/ad672570
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-reference: http://www.dinkumware.com/manuals/reader.aspx?lib=c99
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
Nov 14 '05 #7
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

Nov 14 '05 #8

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

Similar topics

7
by: Christopher Jeris | last post by:
I am relatively new to JavaScript, though not to programming, and I'm having trouble finding the idiomatic JS solution to the following problem. I have a table with (say) fields f1, f2, f3. I...
2
by: Remi Bastide | last post by:
Is is possible to initialize a javascript associative array inline, as you would do in PHP, e.g. : <?php $a = array("abc" => "def", "ghi" => "jkl"); ?>
7
by: Frank M. | last post by:
I'm trying to declare an array of pointers to structures so that I can make the last element a NULL pointer. I figure that it would more easily allow my library routines to know when to stop...
18
by: Vasileios Zografos | last post by:
Hello, can anyone please tell me if there is any difference between the two: double Array1; and
3
by: Louis Caron | last post by:
I am facing the following problem: - I have to build a const array containing functions pointers - the indexes for this array are generated automatically by a tool (not my property) How do I...
3
by: mark.bergman | last post by:
Running lint on code initialising a local 2-D array gives a warning. void f(void) { int a = { 0 }; ... lint gives "warning: Partially elided initialisation..." Should this be happening,...
15
by: jamx | last post by:
How can you initialize an array, in the initialization list of a constructor ?? SomeClass { public: SomeClass() : *init here* { } private: int some_array; };
14
by: dan | last post by:
I would like to have the preprocessor automatically generate the number of array elements requested. Each element is zero. The elements get pasted into a larger array. The other elements may be...
31
by: mdh | last post by:
I am still having a problem understanding K&RII on p 112. I have looked at the FAQs --which I am sure answer it in a way that I have missed, so here goes. A 2-dim array, (per K&R) is really a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...

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.