When writing small programs to test, it is a nuisance that compilers
replace any sequence of operations that can be worked out at compile
time, with the constant value.
Typically, I make such constant values be volatile, which forces the
compiler to load them. But volatile also forces other different
behavior so it changes the way the program is compiled.
I could use a function like rand() but that requires using a library,
which I prfer not to do as that also changes the program.
Is there any simple way a C program can assign a value to some
variable, such that the value is not known at compile time, without
using a library function?
Thanks,
Chris
====================
Chris Bore
www.bores.com
What are you _really_ trying to do? Do you want to compile in values
Is there any simple way a C program can assign a value to some
variable, such that the value is not known at compile time, without
using a library function?
Richard Owlett wrote:
...
You might wish to investigate FORTH .
...
I invite Jerry Avins to jump in at this point as he is a more
accomplished FORTH programmer than I.
Chris wants to know how to make his C compiler do his bidding. Telling
him about another compiler might be useful, but maybe not. Telling him
about a compiler for another language seems to me to be out of place.
Jerry
Chris wants to know how to make his C compiler do his bidding.
You might wish to investigate FORTH .
I invite Jerry Avins to jump in at this point as he is a more
accomplished FORTH programmer than I.
Chris wrote:
Is there any simple way a C program can assign a value to some
variable, such that the value is not known at compile time, without
using a library function?
Is the value indeed not known at compile time? If it is not, and
the compiler is assuming it is, I'd like to see the code. If it is,
and you'd like the compiler to assume it isn't, I'd ask why.
Chris Bore wrote:
When writing small programs to test, it is a nuisance that compilers
replace any sequence of operations that can be worked out at compile
time, with the constant value.
Typically, I make such constant values be volatile, which forces the
compiler to load them. But volatile also forces other different
behavior so it changes the way the program is compiled.
I could use a function like rand() but that requires using a library,
which I prfer not to do as that also changes the program.
Is there any simple way a C program can assign a value to some
variable, such that the value is not known at compile time, without
using a library function?
Is the value indeed not known at compile time? If it is not, and
the compiler is assuming it is, I'd like to see the code. If it is,
and you'd like the compiler to assume it isn't, I'd ask why.
What are you _really_ trying to do? Do you want to compile in values
that are different for each compile but still constant? Do you want to
have constants that can be modified by a debugger? What?
When writing small programs to test, it is a nuisance that compilers
replace any sequence of operations that can be worked out at compile
time, with the constant value.
Typically, I make such constant values be volatile, which forces the
compiler to load them. But volatile also forces other different
behavior so it changes the way the program is compiled.
I could use a function like rand() but that requires using a library,
which I prfer not to do as that also changes the program.
Is there any simple way a C program can assign a value to some
variable, such that the value is not known at compile time, without
using a library function?
When writing small programs to test, it is a nuisance that compilers
replace any sequence of operations that can be worked out at compile
time, with the constant value.
Typically, I make such constant values be volatile, which forces the
compiler to load them. But volatile also forces other different
behavior so it changes the way the program is compiled.
I could use a function like rand() but that requires using a library,
which I prfer not to do as that also changes the program.
Is there any simple way a C program can assign a value to some
variable, such that the value is not known at compile time, without
using a library function?
When writing small programs to test, it is a nuisance that compilers
replace any sequence of operations that can be worked out at compile
time, with the constant value.
Typically, I make such constant values be volatile, which forces the
compiler to load them. But volatile also forces other different
behavior so it changes the way the program is compiled.
I could use a function like rand() but that requires using a library,
which I prfer not to do as that also changes the program.
Is there any simple way a C program can assign a value to some
variable, such that the value is not known at compile time, without
using a library function?
Is the value indeed not known at compile time? If it is not, and
the compiler is assuming it is, I'd like to see the code. If it is,
and you'd like the compiler to assume it isn't, I'd ask why.
My interpretation of Chris' post is that he wants to test some computational
code with input parameters that de facto are known at compile time for his
test routine, since he defined them. The parameters are not known at
compile time for "the real program." I can understand that things change in
the two cases, depeding on how the test is implemented. I am very curious
about an application where such details become as important as they apparently are in this case.
Additional comment: Why not disable optimization? Anyways, it seems you
are only debugging the code, so why not turn-off optimization?
Users browsing this forum: No registered users and 0 guests