public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Earnshaw <rearnsha@arm.com>
To: "Christian Häggström" <97nv46@skola.kiruna.se>
Cc: rearnsha@arm.com
Subject: Re: Volatile constants?
Date: Thu, 30 Mar 2000 04:21:00 -0000	[thread overview]
Message-ID: <200003301221.NAA26580@cam-mail2.cambridge.arm.com> (raw)
In-Reply-To: <s8e31eb4.024@ymer>

> /* Okay I forgot the parenthesis, but that was not my point */
> 
> The GCC manual says "An Inline Function is As Fast As a Macro",
> but when I compile this (as C code), I got error "initializer element is not constant" on
> 's' initialization.
> 
> inline int abs1(int x) {
>     return x<0 ? -x : x;
> }
> #define abs2(x) ((x)<0 ? -(x) : (x))
> 
> int r = abs1(-7);
> int s = abs2(-7);
> 
> Is there any option I have to pass?
> 
> >I don't get that error message. Here is what my compiler says: ...
> 
> Okay you use g++. I use the c compiler.
> g++ don t generate an error (not even a warning) for this,
> but makes an constructor function, 'static_initialization_and_destruction'-something
> That is not what I want and it is NOT as fast as a macro.
> 
> >I think you should upgrade to gcc-2.95.2.
> I compiled with that version, yes
> 
> I ll be glad for any help
> 


An inline function is NOT a macro, it's still a function.  You can't use a 
function as an initializer for a static extent variable in C.

Speed has nothing to do with it; the semantics are different.

Now if the manual said "an inline function is the SAME as a macro", then 
you would have a legitimate complaint.  But it doesn't, so you don't.

R.


  reply	other threads:[~2000-03-30  4:21 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-03-29 23:31 Christian Häggström
2000-03-30  4:21 ` Richard Earnshaw [this message]
  -- strict thread matches above, loose matches on Subject: below --
2000-04-03  2:33 Christian Häggström
     [not found] <s8e49edd.056@ymer>
2000-03-31  3:17 ` Richard Earnshaw
2000-03-31  2:50 Christian Häggström
2000-03-29  4:57 Christian Häggström
2000-03-29  7:41 ` Erik Mouw
2000-03-29  9:53   ` Alasdair Baird
2000-03-29 10:05     ` Erik Mouw
2000-03-29  7:45 ` Kevin Handy
2000-03-29 12:18   ` Andi Kleen
2000-02-22  0:52 Christian Häggström

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200003301221.NAA26580@cam-mail2.cambridge.arm.com \
    --to=rearnsha@arm.com \
    --cc=97nv46@skola.kiruna.se \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).