473,396 Members | 2,036 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 declaration

SRR
Can anyone tell me if it is really possible to do declare 100
variables without "explicitly typing it"?
Consider the following:

int var1=0;
int var2=0;
...........
............
int var99=0;
int var100=0;

The job is to write a "short" macro which when used, pastes the above
declarations in the code.

Feb 26 '07 #1
10 2168
You'll probably be better off using an array.

Rachael
Feb 26 '07 #2
On Feb 26, 3:00 pm, "SRR" <SRRajesh1...@gmail.comwrote:
Can anyone tell me if it is really possible to do declare 100
variables without "explicitly typing it"?
Consider the following:

int var1=0;
int var2=0;
..........
...........
int var99=0;
int var100=0;

The job is to write a "short" macro which when used, pastes the above
declarations in the code.
The easiest way to do it is probably
int var[100]={0};
where you declare an array rather than 100 variables. Whenever you
would use one of your 100 variables, you can just write an extra pair
of square brackets to get the same effect; and you get the added
benefit of being able to do loops over the variables without having to
write everything out by hand. (I don't thing it's possible to do what
you originally with a '"short"' macro, although it's definitely
possible to do it with a set of macros shorter than what it would take
to do the whole thing by hand.)
--
ais523

Feb 26 '07 #3
SRR <SR**********@gmail.comwrote:
Can anyone tell me if it is really possible to do declare 100
variables without "explicitly typing it"?
I can tell you that this exact question was asked less than two weeks
ago:

http://groups.google.com/group/comp....0f7e5841c47817

It's typically a good idea to do at least a cursory search of the
group's archives before asking a question.

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
Feb 26 '07 #4
SRR wrote On 02/26/07 10:00,:
Can anyone tell me if it is really possible to do declare 100
variables without "explicitly typing it"?
Consider the following:

int var1=0;
int var2=0;
..........
...........
int var99=0;
int var100=0;

The job is to write a "short" macro which when used, pastes the above
declarations in the code.
It's certainly possible, given a suitably lenient
definition of "short."

Under any definition, though, it's a stupid thing
to do. Given those declarations, how will you use the
hundred declared variables? Answer: For each operation
you want to perform you will need to write a hundred
versions of the statement that performs it, plus some
more code to choose which of the hundred statements you
want to execute. You will type your little fingers to
the bone. You will make at least two typographical
errors, at least one of which will escape the notice of
the compiler, e.g.

switch (which) {
case 1: var1 = x; break;
case 2: var2 = x; break;
...
case 85: var85 = x; break;
case 86: var85 = x; break;
...
case 99: var99 = x; break;
case100: var100 = x; break;
}

.... and you will have made far more trouble for yourself
than I would wish on anyone.

--
Er*********@sun.com
Feb 26 '07 #5
SRR wrote:
Can anyone tell me if it is really possible to do declare 100
variables without "explicitly typing it"?
Consider the following:

int var1=0;
int var2=0;
..........
...........
int var99=0;
int var100=0;

The job is to write a "short" macro which when used, pastes the above
declarations in the code.
Suppose the answer was "yes". What would you really have gained?

Suppose the answer was "no". What would you have lost?

Suppose the answer was "yes, for some value of 'short', but the
result is an unmaintainable and pointless mess." What would you
have learned?

--
Chris "electric hedgehog" Dollin
"If there is a problem, you must confess it, Mr Chaplin."
Mr Carter, /The Beiderbeck Affair/

Feb 26 '07 #6
SRR wrote, On 26/02/07 15:00:
Can anyone tell me if it is really possible to do declare 100
variables without "explicitly typing it"?
Consider the following:

int var1=0;
int var2=0;
..........
...........
int var99=0;
int var100=0;

The job is to write a "short" macro which when used, pastes the above
declarations in the code.
Why do you need 100 variable rather than 1 array or 100 elements? It
seems like a stupid requirement to me.
--
Flash Gordon
Feb 26 '07 #7

SRR wrote:
Can anyone tell me if it is really possible to do declare 100
variables without "explicitly typing it"?
Consider the following:

int var1=0;
int var2=0;
..........
...........
int var99=0;
int var100=0;

The job is to write a "short" macro which when used, pastes the above
declarations in the code.
How are you going to use them then? Write another set of macros?

Forget such nonsense and use arrays. That's what they're there for.

Feb 26 '07 #8
On 26 Feb, 15:00, "SRR" <SRRajesh1...@gmail.comwrote:
Can anyone tell me if it is really possible to do declare 100
variables without "explicitly typing it"?
Consider the following:

int var1=0;
int var2=0;
..........
...........
int var99=0;
int var100=0;

The job is to write a "short" macro which when used, pastes the above
declarations in the code.
Why would you want to do that, when it seems fairly clear that what
you need here is an array?

Are you also looking for a "short" macro to generate the accesses to
these variables?

Feb 26 '07 #9

"SRR" <SR**********@gmail.comwrote in message
news:11**********************@j27g2000cwj.googlegr oups.com...
Can anyone tell me if it is really possible to do declare 100
variables without "explicitly typing it"?
Consider the following:

int var1=0;
int var2=0;
..........
...........
int var99=0;
int var100=0;

The job is to write a "short" macro which when used, pastes the above
declarations in the code.
Your job is to find a different instructor. The one who assigned this
needs to be fired, unless he/she can say why such nonsense could
really be useful.
--
Fred L. Kleinschmidt
Feb 26 '07 #10
SRR wrote:
Can anyone tell me if it is really possible to do declare 100
variables without "explicitly typing it"?
Consider the following:

int var1=0;
int var2=0;
..........
...........
int var99=0;
int var100=0;

The job is to write a "short" macro which when used, pastes the above
declarations in the code.
int var[100]={0};
Easy to extend to any number of vars you want.
And all set to zero.
Feb 26 '07 #11

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

Similar topics

4
by: Steven Woody | last post by:
i am using a third-party library (mockpp), which comes in many macro for use. for example MOCKPP_CHAINER_FOR_EXT(MyMock, do, ext) myDo (&myMock); it declared and initialized a 'myDo' object in...
27
by: Ken Human | last post by:
I want to generate every possible 16 character combination of the characters 0-9, A-Z, and a-z programatically. My current code follows: #include <stdio.h> #include <ctype.h> int main() {...
3
by: junky_fellow | last post by:
Consider the following piece of code: $ cat a.c extern int func(int); #define func(i) (i+i) int main(void) { (func)(10); } On preprocessing the above code,
4
by: ethan | last post by:
Hi All, I'd like ask some question about macro. If I define a variable set, such as {5, 2, 10} or {1,3}. #define X {5,2,10} 1) Is it possible to write a macro to get the number of items...
3
by: zhangyue.zl | last post by:
Before I thought C is simple and convient , but now I dont think so.There is really some ugly thing in C.Today I see some macro declaration like this: void va_end (va_list); /* Defined in...
2
by: srinu.fsl | last post by:
there's a MACRO call : MACRO1(cnf) and its expansion is : #define MACRO1(cnf) (((cnf) != TRUE)? (CLEANUP(FAIL)):(err = SUCCESS)); #define CLEANUP(a)
2
by: dis_is_eagle | last post by:
Hi.If I define a macro which contains a variable declaration,then during expansion the declaration will not be placed at the beginning of the program,but somwhere within it.How can I overcome it? ...
34
by: Umesh | last post by:
how to convert a program to a function/macro and put it in a header file? is there any shortcut method for this? thanks.
13
by: Guillaume Dargaud | last post by:
Hello all, I tried to write a macro to check if a system is big endian or little endian with no success. Don't get me wrong, I have no problem writing a function or a one liner to do that, but I...
36
by: sh.vipin | last post by:
how to make large macro paste the code as it is Problem Explanation '-- For example in the program below /* a.c - starts here */ #define DECL_VARS() \ unsigned int a0;\ unsigned int a1;\...
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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...

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.