force the (gfortran) compiler to not optimize out a variable

David Brown
Thu Jul 28 14:24:30 GMT 2022

To be able to easily identify the version of an executable binary, we embed
a version string in the code, i.e.
character(len=64)   :: vers='<<<vers_bltr4_1.1.0.0>>>'//achar(0)
character(len=256) c256

and then use the strings command to (we're running redhat) to be able to
quickly identify the version of the executable, i.e.
[db@VI1 src]$ strings ../bin/bltr4.exe | grep "<<<ver"

The only problem is that to make sure the variable vers does not get
optimized out by the compiler, I have to include code like this
c256=vers    !needed so version string does not get optimized out by

We do need to make sure the code is optimized, but having to include that
above assignment statement is not only somewhat obtuse but in some edge
cases chews up resources (some of the programs are very time/resource
sensitive).  I've tried various work arounds, but in summary the above
assignment seems to be the only way to insure the compiler does not
optimize out the vers string.

Is there any way to force the compiler to keep a variable in the
executable, yet otherwise have the optimizer on?

Thanks in advance


David Brown
Eckhardt Trading Company
300 S. Wacker Drive, Suite 1080
Chicago, IL 60606
Tel:  312-765-0565 x1006



message (including
any attachments) contains confidential information 
intended for a specific individual
and purpose and is protected by law. Any 
use, distribution, disclosure, alteration,
copying or re-transmittal by 
persons who are not intended recipients of this
email may be a violation of 
law and is strictly prohibited. If you are not the
intended recipient, 
please permanently delete all copies of this e-mail and any
from your computer system and destroy any hard copies. This e-mail
and any 
attachments hereto are for informational purposes only and should not
construed as an offer to provide advisory services, or sell interests in 
investment vehicle managed, by the Trading Advisor or its affiliates. 
information regarding trading performance must be considered in 
with the appropriate disclosure documents.

More information about the Gcc-help mailing list