Velocity Reviews > How is it possible to use a constant in a variegate way?

# How is it possible to use a constant in a variegate way?

Zottel
Guest
Posts: n/a

 12-11-2007
> Why? An array is the appropriate solution.
>
> You could initialise the array thus:
>
> int konst[] = { KONST1, KONST2, KONST3 };
>
> --
> Ian Collins.

For me Ian, of course it is an academic quest ... have my special thanks
@ll for your helpfully response.

Wouter Bergmann Tiest
Guest
Posts: n/a

 12-11-2007
On Mon, 10 Dec 2007, Zottel wrote:

> I like to use couple of constant in comination with an variable to
> change the name of the constant.

If you don't want to use an array to save on dynamic memory allocation,
you could use an all-constant approach:

#define KONST1 13
#define KONST2 7
#define KONST3 47
#define KONST(i) (i==1?KONST1i==2?KONST2:KONST3))

main() {
int c = getchar()-48;
printf("c = %d, KONST = %d\n",c,KONST(c));
return 0;
}

Regards,

Wouter Bergmann Tiest

E-mail: http://www.velocityreviews.com/forums/(E-Mail Removed) WWW: http://www.phys.uu.nl/~bergmann/
** Life is complex: it has real and imaginary parts **

 Thread Tools

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post Edward A. Falk C Programming 1 04-04-2013 08:07 PM Victor Porton Perl Misc 7 12-11-2007 09:10 PM Tor Erik Soenvisen Python 14 11-23-2006 09:57 PM Martin Magnusson C++ 2 10-08-2004 08:41 AM Christopher M. Lusardi C++ 1 09-02-2004 07:43 AM

Advertisments