|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
Symbolic Constants - Advantages
Hey,
I recently started using C and I've got a question about the advantages of using Symbolic Constants versus variables. I'm guessing that there is some kind of advantage as far as resources go since you can't change a Symbolic Constant after its defined(as opposed to changing a var after its declared), but I can't quite work out what that would be. Can anyone clear this up? Thanks in advance.
__________________
- dsb - ![]() Perl Guy |
|
#2
|
|||
|
|||
|
Yes.
Symbolic constants are evaluated by the PRE-processor, i.e. they are re-written as literal values, not as variables. this has some nice side-effects that you can do using symbolic defines eg. macros and functions inside them. run-time access to symbolic constants should be significantly faster than access to variables. opposite to that, variables (and constants) are evaluated by the processor (compiler).
__________________
-- Manuel Hirsch - Linux, FreeBSD, programming, administration articles, tutorials and more. |
|
#3
|
|||
|
|||
|
Thanks.
I figured it was something like that but didn't know exactly what, or where to look something like that up. Perhaps it would've been explained further in the book I'm using to learn, but I didn't want to go further without knowing why I should use them. I guess they are pretty much like hardcoding values, except that you can give them a meaningful name for the sake of code clarity. Thanks again. You da man ![]() |
|
#4
|
|||
|
|||
|
Quote:
And, if you use the constant in several places, all you need to do is change the line #define MAX_SIZE 225 (or whatever it looks like in C), rather than going code mining for all appearances of the value 225, and determining if it needs changing. Saves alot of headaches. General practice for me is, if I'm going to hardcode something, I use a symbolic constant defined in one of my #include files, that way I can modify the program behavior easily without hunting through obscene amounts of code. |
|
#5
|
|||
|
|||
|
you can read everything about C (ansi C(!)) - and all the background in the book by itīs inventors Kernighan and Ritchie. The german title is "Programmieren in C". English is probably literally translated.
but i donīt think this book is for beginners in programming. if you have some pascal or delphi background or you are already doing some C - go for it. itīs worth every single penny ![]() |
|
#6
|
|||
|
|||
|
Quote:
That's the book I'm using. ![]() At this point I need a crash course so I'm going to have to skip some chapters. I've got a programming background though so I'm not that worried about it . |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > Symbolic Constants - Advantages |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|