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]

Re: Preprocess constants.


So if I had a function like this:
  int square_int(int);

And it took a good couple of mins to run. Is there any way to get the
compiler to execute the code only once if I know that the int argument
will never change ? ie.
  ret=square_int((const)5);

Why could it not be smart, and execute code that has hard coded
arguments in the function call. It could produce code (from the above
example):
  ret=25;

This would then execute much faster.

I understand that some function require other initialization functions to
be run before, so it could not be the default behavior, an argument would
have to be used to force the compiler to execute once.

Would this break some standards that GCC is following ?

Thanks.
Again, I am not on the list, so please include me in the reply.

On 30 Jun 2001, Alexandre Oliva wrote:

> On Jun 29, 2001, Paul Faure <paul@engsoc.org> wrote:
>
> > Why will this code not compile ? Can GCC not figure out the strlen() of a
> > constant string at preprocess time ?
>
> The result of a function call is never a compile-time constant, even
> though you may know it is.  Consider applying the sizeof operator to
> the string, so that you get a constant expression as per the Standard
> definition.
>
>

-- 
Paul N. Faure					613.266.3286
Chief Technical Officer, CertainKey Inc.	paul@certainkey.com
Carleton University Systems Eng. 4th Year	paul@faure.ca
Engineering Society Administrator		paul@engsoc.org


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