By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,190 Members | 777 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,190 IT Pros & Developers. It's quick & easy.

Does the following program architecture make sense?

P: n/a
Does the following program architecture make sense?
#include <stdio.h>
#include "test1.c"
#include "sample.cpp"
int main(void){
output();
output();
testmain();
getchar();
return 0;

}
-------------------------------------

#include"test1.c"
#include"sample.cpp"

include *.c and *.cpp at the same time?
Thank You
Best Regards to you all

Dec 3 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"mikelinyoho" <mi*********@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Does the following program architecture make sense?
#include <stdio.h>
#include "test1.c"
#include "sample.cpp"
int main(void){
output();
output();
testmain();
getchar();
return 0;

}
-------------------------------------

#include"test1.c"
#include"sample.cpp"

include *.c and *.cpp at the same time?


Yikes. With this construct you force the preprocessor to include the actual
code of test1.c and sample.cpp into your current file. This will be accepted
by the compiler, although it is not what #include is actually meant for. The
idea is to have the interface in a header file and the actual implementation
in a .cpp (or for example .cxx) file. In order to have the interface
available you include it with the include statement, but you do not do this
for the actual implementation.

C++ supports different compilation units, which basically means that you can
split your program into different files where you maintain the actual
implementation. The compiler will create object files for each of these and
the linker will combine them into an executable. If you split up your
program (and this is actually good practice), you will have to use a
procedure to compile all of the files in your project separately (via a
makefile or project-file) and link them afterwards. With the inclusion of
the .c and the .cpp file you would have to compile one file only, but I
would very much recommend to stay away from this.

Best regards
Chris
Dec 3 '05 #2

P: n/a
mikelinyoho wrote:
Does the following program architecture make sense?
Depends. It sometimes does, but probably not in this case.

#include <stdio.h>
#include "test1.c"
#include "sample.cpp"
int main(void){
Don't use void in an argument list to specify that there is no
argument. It is considered bad style and is redundant.
output();
output();
testmain();
All these statements won't compile.
getchar();
return 0;
}
-------------------------------------

#include"test1.c"
#include"sample.cpp"

include *.c and *.cpp at the same time?


Usually, you won't do that. Ending a file name with .c or .cpp usually
denotes that this file is meant to be compiled alone. Including it in
another .c or .cpp file is not common practice (except sometimes for
templates).

Although the compiler does not care about the file it includes (as long
as it exists), "header" files (ending in .h or .hpp) or standard C++
headers (ending with nothing) are usually the only kind of file which
gets included.

If this is not only a "just curious" question, saying more about the
design or the problem would allow us to help you a bit more.
Jonathan

Dec 3 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.