ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
What is the best way to use constants in C? I have heard that constants can save ram but my question is do you use it on immediate values, variables that don't change, or codes that repeat them selves a lot?
What is the best way to use constants to save ram?
The C code is then compiled in two steps. First, the preprocessor does a search-and-replace and replaces every instance of "MAX" with "1". Then the code is compiled as normal.
As you've guessed by now, you use constants to represent named constants. Another example would be:
#define PI 3.14
Their usual use is to make code more readable, by giving human-readable labels to machine-readable values.
Now please tell us where you learned about using constants to save RAM. That's not what they're for. The amount they save is absolutely negligible unless you're deploying to an embedded controller, and probably is even then.
It's not a big deal because everyone has so much RAM
Only slightly off-topic:
This is a general programming forum, so it isn't necessarily the case that RAM is virtually unlimited (pun intended), for all of us. There are still small processors and micro-controllers that have limited memory, and that also have distinct types of memory, such as ROM/EPROM and RAM. In that context, the term 'constant' takes on additional meaning, because a value stored in ROM cannot be written (in fact, the CPU instruction set may have no instruction to do so). If the CPU boots from ROM, then some 'constants', like literal strings, may need to be copied from ROM to RAM by the startup code. Keeping track of what is writable, and what is not then becomes important.