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

Compile without header

Hi all,

Is it possible to compile a c++ program without header, if possible
please let me know in detail...

***ajlu***

Dec 16 '06 #1
4 1628
ajlu wrote:
Hi all,

Is it possible to compile a c++ program without header, if possible
please let me know in detail...

***ajlu***
It is possible only if the entire program resides in one file. If you want
to refer to anything outside your own code, you have to include the
appropriate headers.
Bo Persson
Dec 16 '06 #2


On Sat, 16 Dec 2006, Bo Persson wrote:
ajlu wrote:
>Hi all,

Is it possible to compile a c++ program without header, if possible
please let me know in detail...

***ajlu***

It is possible only if the entire program resides in one file.
This is not true. For example:

// a.cpp

extern int get_return_code(void);

int main()
{
int rc = get_return_code();
return rc;
}
//---------------

//b.cpp

int get_return_code(void)
{
return 0;
}
//---------------------------------------------------
If you want
to refer to anything outside your own code, you have to include the
appropriate headers.

Now I agree that programming the way I showed above is extremely bad
practice, and should be avoided by all means. The correct solution is of
course using header files.
Emil
>

Bo Persson
Dec 16 '06 #3
Kohn Emil Dan wrote:
On Sat, 16 Dec 2006, Bo Persson wrote:
>ajlu wrote:
>>Hi all,

Is it possible to compile a c++ program without header, if
possible please let me know in detail...

***ajlu***

It is possible only if the entire program resides in one file.

This is not true. For example:

// a.cpp

extern int get_return_code(void);

int main()
{
int rc = get_return_code();
return rc;
}
//---------------

//b.cpp

int get_return_code(void)
{
return 0;
}
//---------------------------------------------------
>If you want
to refer to anything outside your own code, you have to include the
appropriate headers.


Now I agree that programming the way I showed above is extremely bad
practice, and should be avoided by all means. The correct solution
is of course using header files.

I first thought I should mention that you can do the preprocessor's job by
cutting and pasting the headers into your source file.

I then decided not to tell the OP about that. :-)
Bo Persson
Dec 16 '06 #4

ajlu wrote:
Hi all,

Is it possible to compile a c++ program without header, if possible
please let me know in detail...

***ajlu***
Its impossible to carry out a compilation *with* a header. Only source
files can be compiled.
You are aware that the preprocessor substitutes #includes into your
source *before* compilation starts (with respect of the include guards
in those headers). In fact, a compiler doesn't know what a header file
is.

You write (ignoring include guards):
// a.hpp
class A { };
// test.cpp
#include <a.hpp>
int main() { A a; }

Compiler sees:
// test.cpp
class A { };
int main() { A a; }

Dec 16 '06 #5

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

Similar topics

7
by: Victor Hannak | last post by:
I have the following 2 files as part of my project: GenFuncs.h ------------ #ifndef GenFuncsH #define GenFuncsH #include <iostream.h> #include <strstream.h> using namespace std;
7
by: Ensoul Chee | last post by:
I used #include <iostream.h> int m; cout << "Hexadecimal == 0x" << hex << m << endl; to print value of m in hexadecimal mode. But I got the compile error like this couttest.cpp:20 `hex'...
10
by: Jean-David Beyer | last post by:
I have some programs running on Red Hat Linux 7.3 working with IBM DB2 V6.1 (with all the FixPacks) on my old machine. I have just installed IBM DB2 V8.1 on this (new) machine running Red Hat...
15
by: Benjamin Rutt | last post by:
Are there any C tools that can find redundant #includes in a project, so as to shorten compile time? Of course, eliminating single #includes by hand and determining if the recompile fails is one...
10
by: Bart Goeman | last post by:
Hi, I have a question about how to put redundant information in data structures, initialized at compile time. This is often necessary for performance reasons and can't be done at run time (data...
11
by: Marco | last post by:
Is there a standard way using the preprocessor to detect if a given C compiler/library environment provides the C99 <math.h> floating point functions such as: float powf(float x, float y);...
10
by: Martin Jørgensen | last post by:
Hi, I got this piece of code, but I won't compile: #include <iostream> using namespace std; //////////////////////////////////////////////////////////////// struct link ...
5
by: Michael | last post by:
Hi All, I have three very simple files as below. When I try and compile these with g++ -ansi -Wall -pedantic -o crap Base.h Other.h I get an error: Base.h:7: internal compiler error:...
0
by: dot | last post by:
I spent a few headache filled days trying to use GMP on windows (XP pro) I finally got it to work and since I found little help on the Web I thought someone might find what i did useful. ...
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.