473,395 Members | 2,468 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,395 software developers and data experts.

Does the following program architecture make sense?

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
2 2043

"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: mike | last post by:
regards: Does the following programming architecture make sense? http://www.wretch.cc/album/show.php?i=otp&b=1&f=1111993473&p=2 ...
1
by: mike | last post by:
regards: My program logic is following: http://www.wretch.cc/album/show.php?i=otp&b=1&f=1114017894&p=4 from Step1 to Step4 Any positive suggestion is welcome. thank you May goodness be...
24
by: David Mathog | last post by:
If this: int i,sum; int *array; for(sum=0, i=0; i<len; i++){ sum += array; } is converted to this (never mind why for the moment):
11
by: L. Chen | last post by:
The standard says that a char* or void* pointer has the least strict alignment. But I do not know what is a strict alignment. What does that mean?
8
by: Will Chamberlain | last post by:
I came across a rather interesting article this morning and thought I'd share. We all know that Visual Studio is a great IDE, but I think we can all agree that it is adds a dramatic change to how...
3
by: mikelinyoho | last post by:
#include <stdio.h> #include "test1.c" #include "sample.cpp" int main(void){ output(); output(); testmain();
23
by: centurian | last post by:
I have compiled following program with g++/gcc 3.3.1 and "MS Visual C++ 6" and it ran without any errors. Does this thing make any sense? Is it of some use or some problem with grammar/CFG of...
5
by: Anupam Kapoor | last post by:
hi all, i have a fundamental question :o) ! c is said to emulate the von-neumann model of a computer. wherein we have a cpu connected to store via a pipe (i understand that this is a _very_...
3
by: electrician | last post by:
Yes, no GOTO. This is a major blunder on part of the creators of these tools. GOTO gives the programmer the absolute control over the program. Yes, no matter what, a GOTO sends the program to...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.