473,836 Members | 2,084 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

static inline functions

Can someone please tell me what I am doing wrong. I wrote this static
inline function to test another function and I am getting errors which
make no sense to me.

thanks
Jami

/* test2.h */

static inline unsigned int test3(unsigned int aValue)
{
aValue++;
return aValue;
}

--------------------Configuration: test2 - Win32
Debug--------------------
Compiling...
Text2.c
error C2054: expected '(' to follow 'inline'
error C2085: 'test3' : not in formal parameter list
error C2143: syntax error : missing ';' before '{'

error C2054: expected '(' to follow 'inline'
error C2085: 'test3' : not in formal parameter list
error C2143: syntax error : missing ';' before '{'
Error executing cl.exe.

test2.exe - 6 error(s), 0 warning(s)

Feb 28 '06
13 31071
* David Lindauer:

"Alf P. Steinbach" wrote:
* jamihuq:
Actually, defining any function as static tells the compiler that the
function can only be used in the file the function was defined in.

Sorry, that's incorrect.


what does it mean if you declare an inline function static?


Rather, what does it mean if you declare a static function inline.

In that case 'inline' serves no other purpose than as a very vague
optimization hint, which a modern compiler is likely to ignore.

However, the reasons I wrote 'incorrect' above were (1) that the
standard has no notion of file whatsoever, and (2) that an inline static
function can be used in every compilation unit in which it is defined
(e.g. by having some common definition of it #include'd).

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Feb 28 '06 #11
David Lindauer wrote:

what does it mean if you declare an inline function static?

Thanks,

David


Declare a function 'static inline' means each definition of the
function is unique and multiple translation units can each have their
own definition of the function and compilation will still work. In the
final executable file, every required copy of the function object code
is included but will be assigned and loaded at different virtual
address.

Feb 28 '06 #12
On Mon, 27 Feb 2006 16:05:01 -0800, jamihuq wrote:
Can someone please tell me what I am doing wrong. I wrote this static
inline function to test another function and I am getting errors which
make no sense to me.

--------------------Configuration: test2 - Win32
Debug--------------------
Compiling...
Text2.c


Try calling it "Text2.cpp" .

- Jay

Feb 28 '06 #13
Thanks to all posters, but I found why I am getting errors. Actually,
Jay, Fei and some others made me look past the code itself. It seems
that MSVC 6.0 isn't update with the latest C standards. GNU C compiler
is updated to understand inline functions.

After I named the files as .cpp I didn't get any errors or warnings.
Thanks to all and I am now ending this topic.

Jami

Feb 28 '06 #14

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

Similar topics

9
6371
by: Bryan Parkoff | last post by:
I have noticed that C programmers put static keyword beside global variable and global functions in C source codes. I believe that it is not necessary and it is not the practice in C++. Static keyword is useful inside struct, class, and function only unless you want to force local variable to be global variable so static is used. Do you have idea why most programmers do this? Bryan Parkoff
4
7253
by: Sean | last post by:
I am a little confused by the "extern inline and static inline" rules. I understand that "extern inline" guarantees no function storage is created (all are inlined). But the following test seems to contradict what I expect---I found inc_i() is actually compiled as a linkable function in the a.out >g++ main.cpp call_inc.cpp >nm a.out ...... 0804875e W _Z5inc_iv
32
3066
by: lcdgoncalves | last post by:
Hi everyone Is there a real need to use keyword static with functions, if we simply don't declare their prototypes in .h file? Many textbooks avoid to discuss this matter and/or discuss only the usage of static functions. I've been programming for years and I never felt a real need for the "static approach for functions". I don't know if this is a trivial matter since the reserved word
3
5862
by: Steve Folly | last post by:
Hi, I had a problem in my code recently which turned out to be the 'the "static initialization order fiasco"' problem (<http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.12>) The FAQ section describes a solution using methods returning references to static objects. But consider:
2
3147
by: DaTurk | last post by:
Hi, I have an interesting issue, well, it's not really an issue, but I'd like to understand the mechanics of what's going on. I have a file, in CLI, which has a class declared, and a static fuction. Because the class is declared globally, I declare it as static. Is a function with a namespace scope declared as static by default? So, this worked fine when I was accessing the static function inside
5
6527
by: Martin Wells | last post by:
C89 doesn't have inline but I wanted to use inline in my C89-compliant program. Someone suggested to me that I use macros to determine whether inline was supported, and if necessary, simply define it like: #define inline /* nothing */ , and then define the functions within header files with static inline: static inline void Func(void) {}
2
3778
by: Nagrik | last post by:
Dear Group, The book of Bjarne Stroustrup in chapter 5.4.4 says the following "The word static is one of the most overused words in C and C++. For static data members it has both of the common meanings: static as in "statically allocated" as opposed to on the stack or on the free store and static as in "with restricted visibility" as opposed to with external linkage. For member functions, static has the second meaning."
5
5066
by: ciccio | last post by:
Hi, I have a problem with my code that the compiler does not find any inline functions which are static. The simple code example is written below, this is what the compiler throws at me. ] $ g++ main.cpp foo.cpp /home/klaas/tmp/cciAcYgl.o: In function `main':
17
8390
by: Juha Nieminen | last post by:
As we know, the keyword "inline" is a bit misleading because its meaning has changed in practice. In most modern compilers it has completely lost its meaning of "a hint for the compiler to inline the function if possible" (because if the compiler has the function definition available at an instantiation point, it will estimate whether to inline it or not, and do so if it estimates it would be beneficial, completely regardless of whether...
0
9810
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, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9656
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
10527
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
10575
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
10241
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...
1
7774
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6975
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5812
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3102
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.