Multiple Defines on One Line

Sage
Posts: 1,403
Joined: 2005.07
Post: #1
Can that be done? This is just to make my code neater because I do 16 defines and my code is spagetti elsewhere.

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Member
Posts: 370
Joined: 2002.04
Post: #2
I'm pretty sure that this is not possible. You can go the other way, however (one define spanning multiple lines)...

Put them in a separate header file if you don't want it cluttering your other files.

Did you ever wonder why we had to run for shelter when the promise of a brave new world unfurled beneath the clear blue sky?
Quote this message in a reply
Moderator
Posts: 608
Joined: 2002.04
Post: #3
That wouldn't really make your code any neater, anyways.
Quote this message in a reply
Member
Posts: 184
Joined: 2004.07
Post: #4
I assume this is c/c++, in which case if you're relatively new with the language it's also a good idea for constants not do #define them, but to use a const variable instead. That way you get type-checking for free.
Quote this message in a reply
Member
Posts: 370
Joined: 2002.04
Post: #5
It however, would have some interesting applications in the IOCCC... Grin

But yeah, Josh is right - whitespace is good! If your code is spaghetti to the point where you dread reading it, it may be better to reformat it now (possibly even recode some parts) before you get too far away from it. If you can't read it, you generally can't debug it.

Did you ever wonder why we had to run for shelter when the promise of a brave new world unfurled beneath the clear blue sky?
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #6
what is IOCCC, my codes spagetti because I thought it would be funny to program the entire game mechancs in one procedure, I think of wierd things when I dont sleep! But its kind of cool looking that way, its crazy and I like it. Rasp

phydeaux: Its ObjectiveC, Im not relatively new to C but im always learning Grin (ive just never read a book on it). Type checking is not necassary here because all im defining is integers describing the position of graphics in a file.

I think ill move the def's to a seperate file.
thanks a lot

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Member
Posts: 370
Joined: 2002.04
Post: #7
GIYF: http://www.google.com/search?q=IOCCC

It's going to be funny up to the point where you want to change something. Trust me, I've been there. It will be painful later.

If you wish to learn that on your own, I will not stop you Wink

Did you ever wonder why we had to run for shelter when the promise of a brave new world unfurled beneath the clear blue sky?
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #8
hahaha, ive heard about that before its pretty cool, Check the obfuscated Quines (self replicators) though!!! I dont know if my codes up to that standard yet! Yeah ive started breaking it up slightly and making it more legible.

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #9
phydeaux: the "constant variable" approach doesn't work well for C, due to differences in the meaning of "const" between C and C++.
Quote this message in a reply
Oldtimer
Posts: 834
Joined: 2002.09
Post: #10
Keith: care to elaborate on that?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #11
If you put "const int FOO = 3;" in a header file in C, you'll get "multiply defined" link errors for every source file that includes the header. In C++, that'll work correctly.

In order to make it work at all in C, you need to put "static const in FOO = 3;", which will cause a copy of the variable to be emitted for each source file that includes the header, but will avoid the link errors. I'm not sure if it's true any more, but it used to cause GCC to treat it as if it were a global variable rather than an integer constant (much, much slower). If I had to guess, I'd suspect it will be true until GCC 4.1.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Read a text file line by line? jdunehew 6 11,386 Dec 29, 2011 11:54 AM
Last Post: Blacktiger