473,513 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Function bodies in headers

I sometimes see, particularly in wxWidgets, member function bodies
inside of header files. They're never all that long, and it's usually
just constructors and occasional accessors. Question is, doesn't that
create copies in all of the source files that include that header?
Oct 22 '07 #1
5 1397
inmatarian wrote:
I sometimes see, particularly in wxWidgets, member function bodies
inside of header files. They're never all that long, and it's usually
just constructors and occasional accessors. Question is, doesn't that
create copies in all of the source files that include that header?
If you see "inline" functions in header files then there will likely be
a copy in each object file. The linker is supposed to remove dupes in
this case. You must make sure to recompile everything that uses a
header if the function in the header file changes to avoid surprises.
Oct 22 '07 #2
On Oct 22, 5:46 pm, inmatarian <inmatar...@gmail.comwrote:
I sometimes see, particularly in wxWidgets, member function bodies
inside of header files. They're never all that long, and it's usually
just constructors and occasional accessors. Question is, doesn't that
create copies in all of the source files that include that header?
If the function is more than a few lines, the header file functions
will be mapped to regular functions.
This should not result in any code bloat. Only one copy of the
function is present.

Smaller functions will be treated as inline.

--
VisualEther - http://www.eventhelix.com/VisualEther/
Reverse engineer sequence diagrams from Wireshark logs

Oct 23 '07 #3
EventHelix.com wrote:
On Oct 22, 5:46 pm, inmatarian <inmatar...@gmail.comwrote:
>I sometimes see, particularly in wxWidgets, member function bodies
inside of header files. They're never all that long, and it's usually
just constructors and occasional accessors. Question is, doesn't that
create copies in all of the source files that include that header?

If the function is more than a few lines, the header file functions
will be mapped to regular functions.
This should not result in any code bloat. Only one copy of the
function is present.

Smaller functions will be treated as inline.
Oh, I'm sure that a good optomizing compiler would inline the function.
What I'm asking is what would happen with all optimization turned off?
Does the function show up in each compiled object file?
Oct 23 '07 #4
On 23 Ott, 06:58, inmatarian <inmatar...@gmail.comwrote:
Oh, I'm sure that a good optomizing compiler would inline the function.
What I'm asking is what would happen with all optimization turned off?
Does the function show up in each compiled object file?
Uhm, you should get errors like "multiple definition of foo()".
Strange approach, can you show us the code?

Oct 23 '07 #5
On 2007-10-23 06:58, inmatarian wrote:
EventHelix.com wrote:
>On Oct 22, 5:46 pm, inmatarian <inmatar...@gmail.comwrote:
>>I sometimes see, particularly in wxWidgets, member function bodies
inside of header files. They're never all that long, and it's usually
just constructors and occasional accessors. Question is, doesn't that
create copies in all of the source files that include that header?

If the function is more than a few lines, the header file functions
will be mapped to regular functions.
This should not result in any code bloat. Only one copy of the
function is present.

Smaller functions will be treated as inline.

Oh, I'm sure that a good optomizing compiler would inline the function.
What I'm asking is what would happen with all optimization turned off?
Does the function show up in each compiled object file?
Assuming your compiler/linker does not remove any "dead code" when
optimisations are off then you should have one copy in each object file
built from code that included your header. When you then use the linker
to combine those into an executable file only one of those will be kept.

--
Erik Wikström
Oct 23 '07 #6

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

Similar topics

15
4180
by: chirs | last post by:
I am trying to understand a piece of code. In a javascrpit file, there is a function: function ItemStyle(){ var names=; addProps(this,arguments,names,true); }; In the html file, it calls...
1
1417
by: Greg | last post by:
Hi, In a C++/CLR Windows Forms app I notice that there is only a header and no ..cpp for the form. Also event handler bodies are added by the IDE right to the header. What is the philosophy...
7
1849
by: Csaba Gabor | last post by:
I feel like it's the twilight zone here as several seemingly trivial questions are bugging me. The first of the following three lines is a syntax error, while the last one is the only one that...
21
2603
by: Chen ShuSheng | last post by:
Hey, In head file 'stdio.h', I only find the prototype of these two function but no body. Could someone pls tell me where their bodies are ? -------------- Life is magical.
7
3187
by: VK | last post by:
I was getting this effect N times but each time I was in rush to just make it work, and later I coudn't recall anymore what was the original state I was working around. This time I nailed the...
8
1501
by: Yakov | last post by:
I'd like a tool that performed inlining of function bodies of which do not appear in the .h file. Really. gcc on Linux. Yakov
3
1366
by: geekpie | last post by:
private (browser) caches such as Firefox's or IE6's store requests (headers, or for POST requests, headers and the POST data as the body) as well as responses. Is it possible to see these...
4
1385
by: jodleren | last post by:
Hi fellow I read about this here, and I need a simple form to post and mail a simple table (formatting) in HTML. My message is somthing like: <html><body><table.... I have a header as this. ...
9
1531
by: JRough | last post by:
I'm getting the error message that the parameter passed to the function is not a valid resource. The parameter is $result and it is from a query in a switch statement. What do I have to do to get...
0
7388
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,...
0
7545
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...
0
7539
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...
0
5692
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,...
0
4751
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...
0
3240
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...
0
1605
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 ...
1
807
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
461
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...

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.