Go Down

Topic: Reforming datatype practices (Read 4 times) previous topic - next topic

mem

Quote
A #define (and all other preprocessor directives, e.g. #include , #ifdef, etc) are handled by the C preprocessor (cpp) and not the compiler.  #define is a basic search and replace text operation that takes place before the compiler runs.

That is correct but misses the point being made above. The compiler is more likely to optimize values that are #defined than values that are declared as normal variables.  

kg4wsv

Sorry, I should have quoted for clarification.  I wasn't commenting on (or correcting or arguing with) anything you said, mem, I was trying to answer the question "I have always wondered how the #define stuff works".

-j


mem

#7
Nov 19, 2008, 03:51 pm Last Edit: Nov 19, 2008, 03:52 pm by mem Reason: 1
Now I feel bad for sounding harsh  ;)

Jason, thanks for clearing that up  :)

kg4wsv

no problem, didn't sound harsh to me.  tone is difficult to pick up, that's why on the internet we a) don't take it personally, and b) use those smiley things.

on all the points you brought up, we are in violent agreement.  :)

-j


AlphaBeta

#9
Nov 19, 2008, 06:01 pm Last Edit: Nov 19, 2008, 06:09 pm by AlphaBeta Reason: 1
Quote
I think the arduino team is rightly more concerned about how easy an example is for the user to understand than how efficient the code will be.


Ofcourse, but I would argue that it equally easy to comprehend the byte datatype, as opposed to ints. In microcontroller world you are bound to either come across bytes and bits, or if you are an artist using arduino for leds and such, you already know that you need some mega bytes to store tha program. I do think that it is rather intuitive that the byte is a variable that can hold data.

Two last questions about #define:
1)  are the variables then treated as constants by compiler?
2) does not arduino store the defines/constants in a integer datatype? [or does compiler check for how many bytes needed, tried google but no luck]

Go Up