Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


#define SLUGSNACK "WTF WAS DENNIS RITCHIE SMOKING"
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
kot1990
Expert Cheater
Reputation: 1

Joined: 06 Sep 2009
Posts: 131
Location: Greece

PostPosted: Fri Sep 11, 2009 12:40 pm    Post subject: #define SLUGSNACK "WTF WAS DENNIS RITCHIE SMOKING" Reply with quote

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
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Fri Sep 11, 2009 12:49 pm    Post subject: Reply with quote

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
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Fri Sep 11, 2009 2:16 pm    Post subject: Reply with quote

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
View user's profile Send private message
kot1990
Expert Cheater
Reputation: 1

Joined: 06 Sep 2009
Posts: 131
Location: Greece

PostPosted: Fri Sep 11, 2009 3:45 pm    Post subject: Reply with quote

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 Very Happy , 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? Question Question 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
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Fri Sep 11, 2009 3:50 pm    Post subject: Reply with quote

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
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Fri Sep 11, 2009 3:59 pm    Post subject: Reply with quote

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
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Fri Sep 11, 2009 4:07 pm    Post subject: Reply with quote

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
View user's profile Send private message
Cheat Engine User
Something epic
Ban
Reputation: 60

Joined: 22 Jun 2007
Posts: 2071

PostPosted: Fri Sep 11, 2009 4:10 pm    Post subject: Reply with quote

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
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Fri Sep 11, 2009 4:19 pm    Post subject: Reply with quote

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
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Fri Sep 11, 2009 4:25 pm    Post subject: Reply with quote

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. Rolling Eyes

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
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Fri Sep 11, 2009 4:27 pm    Post subject: Reply with quote

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. Rolling Eyes

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
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Fri Sep 11, 2009 4:30 pm    Post subject: Reply with quote

Preprocessor is nasty, only useful thing is #ifdef, and that is still shaky ground.
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Fri Sep 11, 2009 4:33 pm    Post subject: Reply with quote

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
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Fri Sep 11, 2009 4:41 pm    Post subject: Reply with quote

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
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Fri Sep 11, 2009 4:48 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites