473,322 Members | 1,911 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Re: static used in non-static inline function ?

On Oct 9, 6:49Ā*pm, regis <regis.barbanc...@free.frwrote:
Greetings,

static int mode= 1;
static int half0 (int x) { return x / Ā*2; }
static int half1 (int x) { return x >1; }
inline int half Ā*(int x) { return mode ? half1 (x) : half0 (x); }

Since version 4.3, it seems that gcc with -std=c99 warns:
mode Ā*is static but used in inline function half which is not static
half1 is static but used in inline function half which is not static
half0 is static but used in inline function half which is not static
C99 Standard draft 6.7.4.3: "An inline deļ¬nition of a function with
external linkage shall not contain a deļ¬nition of a modiļ¬able object
with static storage duration, and shall not contain a reference to an
identiļ¬er with internal linkage."
Oct 9 '08 #1
1 10372
christian.bau wrote:
On Oct 9, 6:49 pm, regis <regis.barbanc...@free.frwrote:
Greetings,

static int mode= 1;
static int half0 (int x) { return x / 2; }
static int half1 (int x) { return x >1; }
inline int half (int x) { return mode ? half1 (x) : half0 (x); }

Since version 4.3, it seems that gcc with -std=c99 warns:
mode is static but used in inline function half which is not static
half1 is static but used in inline function half which is not static
half0 is static but used in inline function half which is not static

C99 Standard draft 6.7.4.3: "An inline deļ¬nition of a function with
external linkage shall not contain a deļ¬nition of a modiļ¬able object
with static storage duration, and shall not contain a reference to an
identiļ¬er with internal linkage."
The reason for this requirement is that a compiler is free to create
both an actual function with external linkage that has only one
definition, and seperate inline code in every translation unit that
refers to the function. If it isn't meant to be used in mutliple
translation units, it shouldn't have external linkage.

The real function and the inlined equivalents are supposed to have
identical behavior, so it doesn't matter which one is used, and the
compiler is free to make a different choice at different locations in
your code. However, if the function refers to identifiers with
internal linkage, or defines objects of static storage duration, it
could make a difference which one was used. In your case, half1 and
half2 should be identical in every translation unit, so they're not
actually a problem. However, the standard is not intended to require
compilers to be smart enough to notice that fact; referring to them is
illegal.

The real problem is that there will be a separate copy of mode in each
translation unit, so the behavior of different copies of half() could
be different. If you want them to be different, you should declare
half() as static. If you want them to all be the same, remove 'static'
from half0, and half1, and replace static with 'extern' for mode, and
make sure that an actual definition for mode is provided in one an
only one translation unit.
Oct 9 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: fabio de francesco | last post by:
Hello, I have a couple of years of experience with C++. I started studying C++ syntax, then I read the B.Stroustrup's book, and eventually I went through the N.Josuttis' book on how to program...
87
by: Frances Del Rio | last post by:
is there a non-breaking hyphen in HTML?? for example, so a phone no. falls all on one line.. as in.. 1-800-444-5454... (and is not broken into two lines if phone no. occurs near end of a...
25
by: Yves Glodt | last post by:
Hello, if I do this: for row in sqlsth: ________pkcolumns.append(row.strip()) ________etc without a prior:
32
by: Adrian Herscu | last post by:
Hi all, In which circumstances it is appropriate to declare methods as non-virtual? Thanx, Adrian.
5
by: pb648174 | last post by:
I've been doing a bit of reading and have read in quite a few places that an identity column is a good clustered index and that all or at least most tables should have a clustered index. The tool I...
5
by: Ross | last post by:
Hi, I have the following program: #include <stdarg.h> class A { public: A() { } }
2
by: Tessa | last post by:
Hi, We have a .net web application, and are trying to use PrinterSettings.InstalledPrinters to list the printers installed on the webserver. (Windows 2003 server R2, IIS 6, .net framework 2.0.)...
399
by: =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?= | last post by:
PEP 1 specifies that PEP authors need to collect feedback from the community. As the author of PEP 3131, I'd like to encourage comments to the PEP included below, either here (comp.lang.python), or...
12
by: rafalK | last post by:
Hi All, I have a big problem with STAThread attribute. I'm using XNA framework connected with WinForms. XNA is working in non STAThread. I have a problem with displaying CommonDialog forms e.g....
7
by: Benjamin Goudey | last post by:
I have a very large list of integers representing data needed for a histogram that I'm going to plot using pylab. However, most of these values (85%-95%) are zero and I would like to remove them to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shęllīpōpļ 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.