473,407 Members | 2,306 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

How can I compile a file with different constants?

I have a .c file with a general code. It can be compiled with different
constants for different applications. For example

char a[BYTE_SIZE];

where BYTE_SIZE is a constant defined in an external (.h?) file.
Nov 13 '05 #1
5 1570
Valentin Tihomirov writes:
I have a .c file with a general code. It can be compiled with different
constants for different applications. For example

char a[BYTE_SIZE];

where BYTE_SIZE is a constant defined in an external (.h?) file.


Perhaps you want to know about the preprocessor? You can use #define and
control it with #if.
Nov 13 '05 #2
Valentin Tihomirov wrote:
I have a .c file with a general code. It can be compiled with different
constants for different applications. For example

char a[BYTE_SIZE];

where BYTE_SIZE is a constant defined in an external (.h?) file.


Use CHAR_BIT from <limits.h>.
But note that the "size" of a byte as given by sizeof(char) is always 1.
--
Martin Ambuhl

Nov 13 '05 #3
Martin Ambuhl <ma*****@earthlink.net> writes:
Valentin Tihomirov wrote:
I have a .c file with a general code. It can be compiled with different
constants for different applications. For example
char a[BYTE_SIZE];
where BYTE_SIZE is a constant defined in an external (.h?) file.


Use CHAR_BIT from <limits.h>.
But note that the "size" of a byte as given by sizeof(char) is always 1.


I don't think you're answering the OP's question.
--
"Your correction is 100% correct and 0% helpful. Well done!"
--Richard Heathfield
Nov 13 '05 #4
In article <3f**********@news.estpak.ee>,
Valentin Tihomirov <va******@abelectron.com> wrote:
I have a .c file with a general code. It can be compiled with different
constants for different applications. For example

char a[BYTE_SIZE];

where BYTE_SIZE is a constant defined in an external (.h?) file.


If BYTE_SIZE is defined somewhere, well, there is not much you
can do about it. That's that.

If BYTE_SIZE is undefined, then see if your compiler supports a
-D flag. For instance, with gcc you may do:

gcc -DBYTE_SIZE=23 prog.c

--
Rouben Rostamian <ro*******@umbc.edu>
Nov 13 '05 #5
In <3f**********@news.estpak.ee> "Valentin Tihomirov" <va******@abelectron.com> writes:
I have a .c file with a general code. It can be compiled with different
constants for different applications. For example

char a[BYTE_SIZE];

where BYTE_SIZE is a constant defined in an external (.h?) file.


If BYTE_SIZE is defined in a header file, all you have to do is to
include that header before using the BYTE_SIZE macro.

Most compilers also allow you to define macros at compile time, e.g.
via compiler command line options.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Svennglenn | last post by:
I'm working on a program that is supposed to save different information to text files. Because the program is in swedish i have to use unicode text for ÅÄÖ letters. When I run the following...
2
by: Amanda aman_DO_da345 | last post by:
Hi! I've done most of my programming in C/C++ and a little in Perl, though until recently I have stayed away from Perl OOP. Now I'm writing my first suite of classes in Perl, and I wonder how...
7
by: John Dolinka | last post by:
I have a project of several files with #defines to setup a conditional compile. I would like to put these #defines in a single file and change the conditional compile from this one file with the...
5
by: HNguyen | last post by:
Hi all, I don't know how to include the files from an .aspx file using Visual Studio.NET. For example, I have a file containing the constants and I want to use these constants from aspx file....
4
by: Crirus | last post by:
I need a code to be considered only when I test something... How to declare a compile constant..? -- Cheers, Crirus ------------------------------ If work were a good thing, the boss would ...
2
by: Marty | last post by:
Hi, In VB.NET, what happen to constants when compiling? Are they copied at every place they are needed? Or the application has to refer to constants address each time it need it at run time? ...
15
by: steve yee | last post by:
i want to detect if the compile is 32 bits or 64 bits in the source code itself. so different code are compiled respectively. how to do this?
9
by: Sonnich | last post by:
Hi! I want to have a number of strings in another file, which I can include everywhere... but I cannot make them reachable from the top file. I have looked at var and global to to this but...
11
by: Tim H | last post by:
The following program compiles just fine in C, but not in C++. Can anyone explain why? I have a chunk of code that defines stuff like this in headers (without the extern) that I can not easily...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.