473,608 Members | 2,054 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 definition of a function with
external linkage shall not contain a definition of a modifiable object
with static storage duration, and shall not contain a reference to an
identifier with internal linkage."
Oct 9 '08 #1
1 10435
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 definition of a function with
external linkage shall not contain a definition of a modifiable object
with static storage duration, and shall not contain a reference to an
identifier 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
3451
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 with the C++ Standard Library. I am not a professional programmer however I would like to gain more knowledge of the language to get what could be considered the skills you'd expect from a professional developer ( I also know Unix
87
6385
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 line..) (searched for 'hyphen' in FAQ pg, didn't find anything..) thank you.. Frances
25
7587
by: Yves Glodt | last post by:
Hello, if I do this: for row in sqlsth: ________pkcolumns.append(row.strip()) ________etc without a prior:
32
4502
by: Adrian Herscu | last post by:
Hi all, In which circumstances it is appropriate to declare methods as non-virtual? Thanx, Adrian.
5
9715
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 used to generate tables made them all with non clustered indexes so I would like to drop all of them and generate clustered indexes. So my questions is a) good idea? and b) how? There are foreign key references to most of them so those would...
5
2806
by: Ross | last post by:
Hi, I have the following program: #include <stdarg.h> class A { public: A() { } }
2
6213
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.) The printers installed on the web server under the account used by asp.net for this web application are network printers that are shared by other computers that are on our domain. Permission has been granted for everyone to print to them. The...
399
12775
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 to python-3000@python.org In summary, this PEP proposes to allow non-ASCII letters as identifiers in Python. If the PEP is accepted, the following identifiers would also become valid as class, function, or variable names: Löffelstiel,...
12
5049
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. OpenFileDialog. I can't declare a main method as STAThread because of XNA framework. Is there any way to declare form or some method in form as STAThread (I think that a method from Form can invoke OpenFileDialog) maybe I'm wrong. Do you know...
7
6294
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 reduce the amount of memory I'm using and save time when it comes to plotting the data. To do this, I'm trying to find the best way to remove all of the zero values and produce a list of indices of where the non-zero values used to be. For...
0
8087
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8025
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8509
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8493
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8179
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8365
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4053
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2493
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1620
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.