472,993 Members | 2,460 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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_point_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 misunderstanding the concept of inline functions?
Thank you,



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

I would like to create a very simple function:

// header file
inline void point_map() {
PointMap pointMap = get(vertex_point_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 misunderstanding the concept of inline functions?
Yes, you are misunderstanding.

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...@ifi.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_point_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 misunderstanding the concept of inline functions?

Yes, you are misunderstanding.

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
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....
16
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...
47
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...
7
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
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...
12
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?...
37
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...
4
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

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.