Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I write C++ code without headers (repetitive function declarations)?

Is there any way to not have to write function declarations twice (headers) and still retain the same scalability in compiling, clarity in debugging, and flexibility in design when programming in C++?

like image 542
thewreck Avatar asked Jun 16 '09 13:06

thewreck


People also ask

Can we write C program without header?

Yes it is possible to write a simple program without header files, but why would you do that ? Header files are useful to share definitions, constants, functions prototypes, etc between multiple files or modules.

Do you need header files in C?

In C program should necessarily contain the header file which stands for standard input and output used to take input with the help of scanf() and printf() function respectively.

Will your program run without a header file library declared?

All programs run without using any headers whatsoever. However, most programs are compiled using the standard headers to declare the standard functions, and the better programs ensure that all functions are declared before they are used (or are defined as static functions before they are used).

Why are headers needed in C?

The header file eliminates the labor of finding and changing all the copies as well as the risk that a failure to find one copy will result in inconsistencies within a program. In C, the usual convention is to give header files names that end with . h .


1 Answers

Use Lzz. It takes a single file and automatically creates a .h and .cpp for you with all the declarations/definitions in the right place.

Lzz is really very powerful, and handles 99% of full C++ syntax, including templates, specializations etc etc etc.

Update 150120:

Newer C++ '11/14 syntax can only be used within Lzz function bodies.

like image 63
Richard Corden Avatar answered Nov 03 '22 20:11

Richard Corden