473,770 Members | 2,135 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

inline functions provide macro functionality?

Hi everyone,

I would like to create a very simple function:

// header file
inline void point_map() {
PointMap pointMap = get(vertex_poin t_t(), g);
}

// main.cpp

point_map();
pointMap[0] = Point(2.1,5.4); // error, pointMap variable was
not declared

The function definition is not important, I'm using the BOOST graph
library for working with Graph data structures. The important thing is
that I would like the compiler to replace the body of the code shown
above so I can use pointMap later on. This could be done easily by the
preprocessor with a macro (which I don't want to use), but I thought
that the inline statement provided kind of the same functionality
because an inline function just replaces the body of that function.
However, as with regular functions, I have a compiler message saying
that the pointMap variable was not declared in that scope (therefore
showing that no function body was replaced). I'm new to inline
functions, am I misunderstandin g the concept of inline functions?
Thank you,



Jun 27 '07 #1
2 2116
aaragon wrote:
Hi everyone,

I would like to create a very simple function:

// header file
inline void point_map() {
PointMap pointMap = get(vertex_poin t_t(), g);
}

// main.cpp

point_map();
pointMap[0] = Point(2.1,5.4); // error, pointMap variable was
not declared

The function definition is not important, I'm using the BOOST graph
library for working with Graph data structures. The important thing is
that I would like the compiler to replace the body of the code shown
above so I can use pointMap later on. This could be done easily by the
preprocessor with a macro (which I don't want to use), but I thought
that the inline statement provided kind of the same functionality
because an inline function just replaces the body of that function.
No, an inline function is just an ordinary function. The only thing that
makes inline functions different from other functions, is that they can be
defined in multiple translation units (or in english: you put the body in a
header file.)

The keyword inline doesn't mean that the function will actually be inlined,
as the absence of it doesn't mean that the function will not be inlined.
The compiler does as it pleases. (And there exist compilers that can
actually inline functions that are compiled in other translation units.)
However, as with regular functions, I have a compiler message saying
that the pointMap variable was not declared in that scope (therefore
showing that no function body was replaced). I'm new to inline
functions, am I misunderstandin g the concept of inline functions?
Yes, you are misunderstandin g.

http://www.parashift.com/c++-faq-lit...functions.html

--
rbh
Jun 27 '07 #2
On Jun 27, 6:17 pm, Robert Bauck Hamar <roberth+n...@i fi.uio.no>
wrote:
aaragon wrote:
Hi everyone,
I would like to create a very simple function:
// header file
inline void point_map() {
PointMap pointMap = get(vertex_poin t_t(), g);
}
// main.cpp
point_map();
pointMap[0] = Point(2.1,5.4); // error, pointMap variable was
not declared
The function definition is not important, I'm using the BOOST graph
library for working with Graph data structures. The important thing is
that I would like the compiler to replace the body of the code shown
above so I can use pointMap later on. This could be done easily by the
preprocessor with a macro (which I don't want to use), but I thought
that the inline statement provided kind of the same functionality
because an inline function just replaces the body of that function.

No, an inline function is just an ordinary function. The only thing that
makes inline functions different from other functions, is that they can be
defined in multiple translation units (or in english: you put the body in a
header file.)

The keyword inline doesn't mean that the function will actually be inlined,
as the absence of it doesn't mean that the function will not be inlined.
The compiler does as it pleases. (And there exist compilers that can
actually inline functions that are compiled in other translation units.)
However, as with regular functions, I have a compiler message saying
that the pointMap variable was not declared in that scope (therefore
showing that no function body was replaced). I'm new to inline
functions, am I misunderstandin g the concept of inline functions?

Yes, you are misunderstandin g.

http://www.parashift.com/c++-faq-lit...functions.html

--
rbh
Thank you...

Jun 28 '07 #3

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

Similar topics

13
6571
by: A | last post by:
Hi, I'm having problems completing a project in C++. I have been using inline functions in some of my header files. I have only done so for simple functions that only have 1 statement (eg. accessor and mutator methods to access private data members). I would like to know if there are any issues with using inline functions that may have attributed to my errors before I start separting them out into "outline functions". Regards
16
3499
by: ben beroukhim | last post by:
I have huge number of legacy code which use standard files functions. I would like to pass a memory pointer rather than a FILE pointer. I am trying to use FILEs in the code to refer to memory buffers. Basically, I want to be able to use all the standard read and write functions, but I want them to refer to memory locations, rather than disk files. I do not want to touch the legacy code. Does any one know of a library
47
3893
by: Albert | last post by:
So structures are useful to group variables, so you can to refer to a collection as a single entity. Wouldn't it be useful to also have the ability to collect variable and functions? Ask K&R say, C programs consist of variables to store the input and functions to manipulate them. This would make C object-oriented - how cool would that be? Are there any problems with adding the ability to have functions
7
1975
by: jamihuq | last post by:
Hello, I would like to convert the following inline function to a macro. Can someone help? Thx Jami inline char * fromDESC(const char * &aDesC)
33
8903
by: Robert Seacord | last post by:
When writing C99 code is a reasonable recommendation to use inline functions instead of macros? What sort of things is it still reasonable to do using macros? For example, is it reasonable to write type generic functions macros? #define CUBE(I) ( (I) * (I) * (I) ) Is there some more concise set of things where inline functions should be used instead of macros? Multi-statement macros, for example?
12
676
by: sam_cit | last post by:
Hi Everyone, I have few questions on inline functions, when i declare a function as inline, is it for sure that the compiler would replace the function call with the actual body of the function? or is it a call taken by compiler? Second, i see that it is same as what Macro's used to do for c, if so what is the advantage for going in for inline functions than to Macros?
37
9005
by: junky_fellow | last post by:
hi guys, Can you please suggest that in what cases should a macro be preferred over inline function and viceversa ? Is there any case where using a macro will be more efficient as compared to inline function ? thanks for any help in advance ...
4
1498
by: Hua.watson | last post by:
#define ABC_DLL_F_GET(hDll, func_name) \ { \ (fproc_t &)lpfn##func_name = abc_GetProcAddress(hDll, #func_name); \ } If I want to modity this #define macro to something in good C++ style like a inline func, how should I do$B!)(B Thanks
0
9591
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
9425
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
10057
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...
0
9869
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
8883
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6676
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
5312
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2816
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.