473,325 Members | 2,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

all code in .h file


Is there any criteria regarding where the code should be placed, .h
file or .cc (.cpp) file? I recently came across a project
(http://cvs.sourceforge.net/viewcvs.py/slate/slate/) where all the
code is placed in .h files, there is no single .cc (.cpp) file! I'm
wondering whether there is any obvious advantage of doing this.
Jul 19 '05 #1
7 2745
"Zimmen Gnauh" <ya*********@yahoo.com> wrote in message
news:m2************@yahoo.com...

Is there any criteria regarding where the code should be placed, .h
file or .cc (.cpp) file? I recently came across a project
(http://cvs.sourceforge.net/viewcvs.py/slate/slate/) where all the
code is placed in .h files, there is no single .cc (.cpp) file! I'm
wondering whether there is any obvious advantage of doing this.


the classes in Slate seemed to be all Template classes. The implemetion of
methods in a template class must be in the .h file. And also inline
functions must be in .h file. Everything else being in the .h file in my
opinion is bad programming practice.

Ali R.
Jul 19 '05 #2
template classes need to be in .h files, so probably the project only
has template classes.
Zimmen Gnauh wrote:
Is there any criteria regarding where the code should be placed, .h
file or .cc (.cpp) file? I recently came across a project
(http://cvs.sourceforge.net/viewcvs.py/slate/slate/) where all the
code is placed in .h files, there is no single .cc (.cpp) file! I'm
wondering whether there is any obvious advantage of doing this.


Jul 19 '05 #3
"Zimmen Gnauh" <ya*********@yahoo.com> wrote...
Is there any criteria regarding where the code should be placed, .h
file or .cc (.cpp) file? I recently came across a project
(http://cvs.sourceforge.net/viewcvs.py/slate/slate/) where all the
code is placed in .h files, there is no single .cc (.cpp) file! I'm
wondering whether there is any obvious advantage of doing this.


Names do not matter. If your compiler compiles files with
extension '.h', place your code there if you want. However,
you cannot have all headers and no compilable source unless
your product is a library (like a template library, e.g.)
and is not supposed to exist as a runnable program.

Victor

Jul 19 '05 #4
Code in header files will run faster since it is intrinsically inlined but
will bloat your program's size since each function call will resolve to a
copy of the function's code. This also means that recursive functions cannot
be (or take extra care to code) in headers (see recursive function templates
for examples). The speed increase is related to function call overhead,
however, so only small functions will be significantly improved.

If you are developing a library for binary release, code in header files
will be publicly visible, so the more code that is there, the less secret
your implementation becomes.

Ray
Jul 19 '05 #5
Ray Gardener wrote:
The speed increase is related to function call overhead,
however, so only small functions will be significantly improved.


But not all small functions will be significantly improved,
and those that are will need to be called 1000s perhaps
1,000,000 of times before you'll be able to measure the
significance.
Jul 19 '05 #6
"Ray Gardener" <ra**@daylongraphics.com> wrote in message
news:0PRsb.382917$6C4.8840@pd7tw1no...
Code in header files will run faster since it is intrinsically inlined but
That depends. As far as I know, the following function will not be
inlined, even though it is in the header

--- test.h ---

class my_test
{
void func ();
};

my_test::func () {}

--- end test.h ---

because it is missing the implicit or explicit inline specifier.
will bloat your program's size since each function call will resolve to a
copy of the function's code. This also means that recursive functions cannot be (or take extra care to code) in headers (see recursive function

templates

Whether function code is inside the header or the cpp file does not
affect whether or not it can be recursive or not. No extra care needs to be
taken for a recursive function inside a header. It's the compiler's
responsibility to compile the code and stop (or not allow) inline recursion
whenever necessary.

regards
--
jb

(replace y with x if you want to reply by e-mail)
Jul 19 '05 #7
The problem with putting all the code in header files is that
increases the dependencies involved in including a header file.

Thus any file including an object gets all the header file
depencies of the class. When the code is placed in h and cpp files,
including the header file adds depencies only for variables that
are *required* for the header file.

See the following article to clarify this:

http://www.eventhelix.com/RealtimeMa...dePatterns.htm

Sandeep
--
http://www.EventHelix.com/EventStudio
EventStudio 2.0 - Generate Sequence Diagrams and Use Case Diagrams in PDF
Jul 19 '05 #8

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

Similar topics

1
by: Marc | last post by:
Hello I have a website where I can upload a file via a form. The uploaded file is stored in a MySQL database. When dloading te file I get a save as... dialog box, letting me save the file. But...
2
by: Ric | last post by:
im new to asp.net. from what i understand, you have the aspx file (presentation), user-control(ascx file), code-behind(vb file) and components(compiled vb and dll files). the aspx file contains a...
29
by: John Rivers | last post by:
Hello, What good reason there is for not allowing methods in ASPX pages I can't imagine, but here is how to get around that limitation: (START) <body MS_POSITIONING="FlowLayout"> <form...
19
by: Alan Silver | last post by:
Hello, I have been developing ASP.NET with a text editor so far (better way to learn initially), and have now been trying Visual Web Developer. I want to create a project for an existing site...
4
by: jason.awlt | last post by:
Greetings, I recently being bugged by the following error on my DB2. SQL0902C SQLSTATE = 58005 Reason Code = 14 This error comes out everytime i tried to insert some record to a table...
1
by: cnixuser | last post by:
Hello, I am having a problem that I believe is related to the way a stream reader object looks for a text file by default. What I am doing is using a StreamReader object to read the text of a text...
3
by: melbourno | last post by:
I have a Perl script that I run and the out come as showing below: Log chain 1: Reading: server 2\08120700.mls Reading: server 2\08120900.mls Reading: server 1\08121100.mls Log chain 2: ...
4
NeoPa
by: NeoPa | last post by:
Introduction: Macro Security Levels in MS Office applications are recommended to be set to High. This stops any VBA code associated with a project from running, unless it is signed (with a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.