How can I compile a file with different constants?

V

Valentin Tihomirov

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.
 
O

osmium

Valentin said:
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.
 
M

Martin Ambuhl

Valentin said:
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.
 
B

Ben Pfaff

Martin Ambuhl said:
Valentin said:
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.
 
R

Rouben Rostamian

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
 
D

Dan Pop

In said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,085
Messages
2,570,597
Members
47,218
Latest member
GracieDebo

Latest Threads

Top