473,511 Members | 14,825 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

define array

I have a file.h that have all my definitions and I need to define a
array to use in my software, but I don´t know how can I do it.

My define´s that cause error:

....
#define ERROR_SAMPLE1 123
#define ERROR_SAMPLE2 124
....
#define FUNCTIONS_EMP { 20, 15, 22, 53, 34)
....

I´d like to use FUNCTIONS_EMP in my software like a ARRAY, sample:

....
Log( ERROR_SAMPLE1 ); ==same Log( 123 );
....
Log(FUNCTIONS_EMP[1]; ==same Log( 15 );
....

Thanks for help

===========================================
Protuguês - Brasil

Eu tenho um arquivo file.h que contém todas as minhas definições e
preciso definir um array para usar no meu software, mas não estou
sabendo como fazer isto.

Minha definição que causou erro foi:

....
#define ERROR_SAMPLE1 123
#define ERROR_SAMPLE2 124
....
#define FUNCTIONS_EMP { 20, 15, 22, 53, 34)
....

Eu gostaria de usar FUNCTIONS_EMP no meu software como um ARRAY,
exemplo:

....
Log( ERROR_SAMPLE1 ); ==same Log( 123 );
....
Log(FUNCTIONS_EMP[1]; ==same Log( 15 );
....

Obrigado pela ajuda.

Jul 12 '06 #1
2 11337

<ma********@gmail.comwrote in message
news:11*********************@s13g2000cwa.googlegro ups.com...
I have a file.h that have all my definitions and I need to define a
array to use in my software, but I don4t know how can I do it.

My define4s that cause error:

...
#define ERROR_SAMPLE1 123
#define ERROR_SAMPLE2 124
...
#define FUNCTIONS_EMP { 20, 15, 22, 53, 34)
...

I4d like to use FUNCTIONS_EMP in my software like a ARRAY, sample:

...
Log( ERROR_SAMPLE1 ); ==same Log( 123 );
...
Log(FUNCTIONS_EMP[1]; ==same Log( 15 );
...

Thanks for help
Instead of using #define for the array, you could define a global const
array in an implementation file, and declare it as extern in the header file
that other implementation files include.

-Howard

Jul 12 '06 #2
<ma********@gmail.comwrote (as near as I can tell, after
cleaning-up some apparent typos):

#define FUNCTIONS_EMP {20, 15, 22, 53, 34}
Log(FUNCTIONS_EMP[1]); // same as Log( 15 );

No, that's not the same thing at all! Let's look at the pre-processed
version of what you wrote (ie, what the compiler sees):

Log({20, 15, 22, 53, 34}[1]); // syntax error

Remember, now, the C preprocessor is just a text editor. It's a
rather good text editor in my opinion. I love it and use it a lot.
But none-the-less, it's just a text editor. It doesn't understand
C++ or any other language. It just processes text. You could use
it to process a novel, or a grocery list. I won't parse C++
statements, extract your meaning, and insert the correct syntax for
you. You have to do that yourself.

So, if you want to define an array, you'll have to do it directly
in C++, like so:
void foo()
{
static const int FUNCTIONS_EMP[5] = {20, 15, 22, 53, 34};
// ...
}

Now THAT will work.

(However, if FUNCTIONS_EMP will ever change, use std::vector
instead. In fact, std::vector is better than built-in arrays
for most array applications, because of bounds checking,
expandibility, member functions, etc. I personally only use
built-in arrays for very small, fixed sets of constant values.)
--
Cheers,
Robbie Hatley
East Tustin, CA, USA
lone wolf intj at pac bell dot net
(put "[usenet]" in subject to bypass spam filter)
http://home.pacbell.net/earnur/
Jul 14 '06 #3

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

Similar topics

9
5696
by: Acacia | last post by:
i get this error on any line with dot notation. Oh, and do I need to use cin.getline(boy.name)?: error:'.':left operand points to 'struct' use '->' This is the program in question: ...
22
4573
by: VK | last post by:
A while ago I proposed to update info in the group FAQ section, but I dropped the discussion using the approach "No matter what color the cat is as long as it still hounts the mice". Over the last...
20
78037
by: Geoff Cox | last post by:
Hello, This may be the answer to a problem I have - or it may not be possible?! Can I have initial values of variable situation and count defined as var situation = 0; var count = 0;
2
2771
by: Jarod | last post by:
Hello I am curious how should I use the array of doubles. The problem is I don't know in advance how much elements would it have, but I can be sure it will be less then let's say 150 or 500. So...
18
2078
by: P.N. | last post by:
Hi! when i define array (any type) then compilator say that array is to large! ?? i need at least 10.000 instead 100. This is for numeric methods in "C" any sugestion? thx Greetings P
15
26395
by: thinktwice | last post by:
char a = { 0 } is it ok?
3
4928
by: jspot | last post by:
I have set up an array that includes the months of the year. <?php // define array $month = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September',...
1
1876
by: Freddy Coal | last post by:
Hi, I don't know how redim an array, My problem whit an example: I define my array Dim Ary as array I put three elements inside my array Ary = Split("one,two,three", ",")
152
9735
by: vippstar | last post by:
The subject might be misleading. Regardless, is this code valid: #include <stdio.h> void f(double *p, size_t size) { while(size--) printf("%f\n", *p++); } int main(void) { double array = { {...
0
7153
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
7371
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
7432
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
5676
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,...
1
5077
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1583
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
452
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.