Does the following program architecture make sense?

M

mikelinyoho

#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
 
N

Nick Keighley

mikelinyoho said:
#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?

it is very unusual to include a ".c" file. It is close to being a
"never do this".
If you want to call things in another ".c" file then link them together
(see
your compiler documentation).

Does your program really contain both C and C++ code?
 
S

santosh

mikelinyoho said:
#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?

If you compile as a C++ program (using a C++ compiler) it may compile.
A C only compiler (or one compiling as C) will reject the contents of
the
"sample.cpp" file, if they contain C++ code.

Although 'include' files can have any suffix, their contents must be
syntactically and semantically correct for the particular program in
which they are included, under a particular compiler operating under
particular switches. The programmer has to figure it out.
 
M

Malcolm

mikelinyoho said:
#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?
Yes.
It is pretty horrible but programs can easily be written in C to compile as
C++, and sometimes you might want to paste together a source file from
multiple includes.
(Normally you would just compile the source files separately and link, but
if you are doing something messy and ugly with globals / statics there might
be a reason for not doing so. As I said, it pretty horrible but not
senseless).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top