This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Controlling the compile within the compiled file?


From: "Ciaran O'Riordan" <ciaran_o_riordan@hotmail.com>


>
> >From: "Shuki Sasson" <shuki_sasson@hotmail.com>
> >
> >Hi all, I came across a problem with the optimizer (-O option) the -O0
> >option get rid of the problem.
> >A question:
> >Can one instruct the gcc compiler to turn option on/off within the
compiled
> >code?
>
> No.  Optimisation is a one-way function.
>
> If you have an expression in your code "(1 + 1)" the optimiser will
> replace this with "2".  The compiled program does not know that the
> programmer typed "(1 + 1)".  I know your talking about more complex
> code but the principle is the same.
>
> You'll have to recompile if you want to change the optimisations.
> If the problem occurs when you use "gcc -O", try -O2, -O3 or -Os.
> If the problem doesn't go away try specifying the optimisation
> switches yourself i.e. gcc -fforce-mem -fomit-frame-pointer (etc.)
>
> Hope this helps
>
I don't think that's what Shuki meant by turning optimization on and off.
He doesn't want to reverse an optimization, just disable it.

Some compilers let you use #pragma directives to disable optimizations
at the function level so that it _doesn't_ collapse "(1 + 1)" into "2".
Again,
that's just the trivial example.

Gcc is almost totally devoid of #pragmas, at least in 2.95.  I don't know
about the current version.  I would definitely like to see some though.

We have a library of several hundred modules that is compiled nightly
by an automated build script (run via cron) on several platforms.  It just
so happens that two of the modules need to be compiled for no optimization
on one platform (Mac OS X) or they cause programs to crash.  If we
could use #ifdefs to #pragma the optimizations out in the source, it would
be a lot easier than mucking around with the script that builds the
makefile.

----
Dave Williss
MicroImages, Inc.
perl -e 'print$i=pack(c5,(41*2),sqrt(7056),(unpack(c,H)-2),oct(115),10);'



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]