View previous topic :: View next topic |
Author |
Message |
kot1990 Expert Cheater
Reputation: 1
Joined: 06 Sep 2009 Posts: 131 Location: Greece
|
Posted: Fri Sep 11, 2009 12:40 pm Post subject: #define SLUGSNACK "WTF WAS DENNIS RITCHIE SMOKING" |
|
|
I've got this code.
Code: | int main()
{
int tSize = 5; //tSize will use 4 bytes of memory as it is an integer.
int table[tSize]; //Will create a table of 5 integers, 5*4 = 20 bytes.
} |
Simple code that creates a table of 5 integers, sum memory will be 24 bytes.
Then if I use #define directive will tSize take any memory?
example:
Code: | #define tSize 5 //does this one allocate any memory for tSize?
int main()
{
int table[tSize]; //20 bytes;
} |
|
|
Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Fri Sep 11, 2009 12:49 pm Post subject: |
|
|
it does not allocate an object. it is a compiler directive. when the compiler sees tSize later in the code it will replace all instances of it with 5
it is like defining a constant
|
|
Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Fri Sep 11, 2009 2:16 pm Post subject: |
|
|
Preprocessor defines are generally useless. I wouldn't touch them with a ten foot pole.
The only place I ever see them used seriously is in tutorial applications for teaching people new to the language.
|
|
Back to top |
|
 |
kot1990 Expert Cheater
Reputation: 1
Joined: 06 Sep 2009 Posts: 131 Location: Greece
|
Posted: Fri Sep 11, 2009 3:45 pm Post subject: |
|
|
Slugsnack wrote: | it does not allocate an object. it is a compiler directive. when the compiler sees tSize later in the code it will replace all instances of it with 5
it is like defining a constant |
Heh then this is better than a constant variable , because this is like
table[5] telling the program directly that the array is size of 5. With an integer variable tSize, the table[tSize] would take the number 5 from tSize indirectly, and I don't need +4bytes.
Edit: But in the final executable who will tell that the array is size of 5? The number should be saved somewhere.
Last edited by kot1990 on Fri Sep 11, 2009 3:50 pm; edited 1 time in total |
|
Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Fri Sep 11, 2009 3:50 pm Post subject: |
|
|
indeed. it is good for things like that where you can just update the definition at the top and all instances would change
|
|
Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Fri Sep 11, 2009 3:59 pm Post subject: |
|
|
Slugsnack wrote: | indeed. it is good for things like that where you can just update the definition at the top and all instances would change |
Except for the fact that in a serious application it would be up to user input to define the number (settings, etc), and not the programmer.
It is, in part, related to this: http://catb.org/~esr/jargon/html/Z/Zero-One-Infinity-Rule.html
I keep forgetting you've never actually programmed anything other than your hobby shit, though, so I suppose you wouldn't actually know that. My bad.
|
|
Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Fri Sep 11, 2009 4:07 pm Post subject: |
|
|
Athaem wrote: | Slugsnack wrote: | indeed. it is good for things like that where you can just update the definition at the top and all instances would change |
Except for the fact that in a serious application it would be up to user input to define the number (settings, etc), and not the programmer.
It is, in part, related to this: http://catb.org/~esr/jargon/html/Z/Zero-One-Infinity-Rule.html
I keep forgetting you've never actually programmed anything other than your hobby shit, though, so I suppose you wouldn't actually know that. My bad. |
you prove time and time again that you're a fuckwit. not everything is based on user input. take a simple example of a listview. a lot of the time we want code that iterates through all the subitems of a given index. instead of hardcoding the number of columns, we could use a #define at the top
but yeah.. obviously no 'serious applications' use listviews. and obviously number of columns in a listview MUST be defined by user input, i mean duhh
try developing and using your brain instead of quoting useless and irrelevant pages to back up the shit you talk from your ass
|
|
Back to top |
|
 |
Cheat Engine User Something epic
Reputation: 60
Joined: 22 Jun 2007 Posts: 2071
|
Posted: Fri Sep 11, 2009 4:10 pm Post subject: |
|
|
Athaem wrote: | Slugsnack wrote: | indeed. it is good for things like that where you can just update the definition at the top and all instances would change |
Except for the fact that in a serious application it would be up to user input to define the number (settings, etc), and not the programmer.
It is, in part, related to this: http://catb.org/~esr/jargon/html/Z/Zero-One-Infinity-Rule.html
I keep forgetting you've never actually programmed anything other than your hobby shit, though, so I suppose you wouldn't actually know that. My bad. | * Athaem jumps in the thread
<Athaem> You are all idiots
<Athaem> Read these PDF's for more information
* Athaem throws googled articles at you
* Athaem leaves
|
|
Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Fri Sep 11, 2009 4:19 pm Post subject: |
|
|
Athaem has clearly failed to understand the main point of the #define directive which is readability, not to provide any extra functionality
Just because you only 'ever see them' in a limited amount of places does not mean that is to say that is the only places they exist. Good job at failing on basic logic.. and completely misunderstanding the point of a preprocessor directive
Another common example:
Code: | #define JMP(frm,to) (((int)to - (int)frm)-5) |
BUT OF COURSE.. THAT SHOULD BE USER DEFINED !!!
Last edited by Slugsnack on Fri Sep 11, 2009 4:25 pm; edited 1 time in total |
|
Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Fri Sep 11, 2009 4:25 pm Post subject: |
|
|
Slugsnack wrote: | you prove time and time again that you're a fuckwit. not everything is based on user input. take a simple example of a listview. a lot of the time we want code that iterates through all the subitems of a given index. instead of hardcoding the number of columns, we could use a #define at the top
but yeah.. obviously no 'serious applications' use listviews. and obviously number of columns in a listview MUST be defined by user input, i mean duhh
try developing and using your brain instead of quoting useless and irrelevant pages to back up the shit you talk from your ass |
Or, you know, you could to it the right way and query the listview for the amount of columns, and use that number for your iteration. This way if we added another column, we wouldn't have to update any shitty preprocessor defines, as the code already knows about it.
That would be doing things right though, and we can't have that here.
Seriously, l2program.
Slugsnack wrote: | Another common example:
Code: | #define JMP(frm,to) (((int)to - (int)frm)-5) |
BUT OF COURSE.. THAT SHOULD BE USER DEFINED !!! |
Common in the world of Slugsnack's hobby apps, maybe. Face it, defines are useless, this would be better off made into an explicit function.
Last edited by Flyte on Fri Sep 11, 2009 4:29 pm; edited 1 time in total |
|
Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Fri Sep 11, 2009 4:27 pm Post subject: |
|
|
Athaem wrote: | Slugsnack wrote: | you prove time and time again that you're a fuckwit. not everything is based on user input. take a simple example of a listview. a lot of the time we want code that iterates through all the subitems of a given index. instead of hardcoding the number of columns, we could use a #define at the top
but yeah.. obviously no 'serious applications' use listviews. and obviously number of columns in a listview MUST be defined by user input, i mean duhh
try developing and using your brain instead of quoting useless and irrelevant pages to back up the shit you talk from your ass |
Or, you know, you could to it the right way and query the listview for the amount of columns, and use that number for your iteration. This way if we added another column, wouldn't have to update any shitty preprocessor defines, the code already knows about it.
That would be doing things right though, and we can't have that here.
Seriously, l2program. |
Adding columns is usually done via a for/while loop with variant as number of columns. But OF COURSE you would rather update the number by hardcoding it
Let me put it more simply for you : YOU CAN'T COUNT SOMETHING USING A FUNCTION UNTIL YOU PUT THOSE SOMETHINGS THERE FIRST
|
|
Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Fri Sep 11, 2009 4:30 pm Post subject: |
|
|
Preprocessor is nasty, only useful thing is #ifdef, and that is still shaky ground.
|
|
Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Fri Sep 11, 2009 4:33 pm Post subject: |
|
|
Slugsnack wrote: | Adding columns is usually done via a for/while loop with variant as number of columns. But OF COURSE you would rather update the number by hardcoding it
Let me put it more simply for you : YOU CAN'T COUNT SOMETHING USING A FUNCTION UNTIL YOU PUT THOSE SOMETHINGS THERE FIRST |
You are incredibly dense. You are the one hardcoding the fucking number by making it a preprocessor definition, you pedantic piece of shit. When you add a column, you add it with a purpose, not some arbitrary reason.
This is about programming a robust piece of code, not some useless code that I can't use anywhere else. Though, I've already established that you are in fact a hobbyist and wouldn't know what a robust program is if it was shoved in your face.
|
|
Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Fri Sep 11, 2009 4:41 pm Post subject: |
|
|
Athaem wrote: | Slugsnack wrote: | Adding columns is usually done via a for/while loop with variant as number of columns. But OF COURSE you would rather update the number by hardcoding it
Let me put it more simply for you : YOU CAN'T COUNT SOMETHING USING A FUNCTION UNTIL YOU PUT THOSE SOMETHINGS THERE FIRST |
You are incredibly dense. You are the one hardcoding the fucking number by making it a preprocessor definition, you pedantic piece of shit. When you add a column, you add it with a purpose, not some arbitrary reason.
This is about programming a robust piece of code, not some useless code that I can't use anywhere else. Though, I've already established that you are in fact a hobbyist and wouldn't know what a robust program is if it was shoved in your face. |
Oh god, I don't know if you're trying to act retarded but you're doing a really good job of it. #define is about readability. The majority of people would rather see numColumns than fucking 7
But no, an obvious professional like you who codes robust programs would clearly rather have the 7
|
|
Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Fri Sep 11, 2009 4:48 pm Post subject: |
|
|
Slugsnack wrote: | Oh god, I don't know if you're trying to act retarded but you're doing a really good job of it. #define is about readability. The majority of people would rather see numColumns than fucking 7
But no, an obvious professional like you who codes robust programs would clearly rather have the 7 |
I would have neither you dumb fuck. Both are hardcoding the number of columns, which is horribly wrong. You add columns with a purpose, you don't add an arbitrary number. If for some reason you needed to iterate over all of the columns without a care of what they represent you would first ask the listview for the number of columns it has, then use that number for your iteration.
Also, I should point out that according to the standard convention, defines are in all caps, which actually reduces readability. The variable you actually mentioned would be explicitly declared as a constant:
Code: | const int numColumns = 7; |
Instead of:
Code: | #define NUMCOLUMNS 7 |
You're your own worst enemy.
|
|
Back to top |
|
 |
|