472,791 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 11291

<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
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
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
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
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
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
by: thinktwice | last post by:
char a = { 0 } is it ok?
3
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
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
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
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.