header-files

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

我们两清 提交于 2019-11-26 12:25:36
问题 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++? 回答1: 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

C/C++ header and implementation files: How do they work?

雨燕双飞 提交于 2019-11-26 12:02:31
问题 This is probably a stupid question, but I\'ve searched for quite a while now here and on the web and couldn\'t come up with a clear answer (did my due diligence googling). So I\'m new to programming... My question is, how does the main function know about function definitions (implementations) in a different file? ex. Say I have 3 files main.cpp myfunction.cpp myfunction.hpp //main.cpp #include \"myfunction.hpp\" int main() { int A = myfunction( 12 ); ... } - //myfunction.cpp #include \

How do header and source files in C work?

跟風遠走 提交于 2019-11-26 11:53:09
问题 I\'ve perused the possible duplicates, however none of the answers there are sinking in. tl;dr: How are source and header files related in C ? Do projects sort out declaration/definition dependencies implicitly at build time? I\'m trying to understand how the compiler understands the relationship between .c and .h files. Given these files: header.h : int returnSeven(void); source.c : int returnSeven(void){ return 7; } main.c : #include <stdio.h> #include <stdlib.h> #include \"header.h\" int

Including C headers inside a C++ program

纵然是瞬间 提交于 2019-11-26 10:58:12
问题 I have a C++ program (.cpp) inside which I wish to use some of the functions which are present inside the C header files such as stdio.h, conio.h, stdlib.h, graphics.h, devices.h etc. I could include the stdio.h library inside my cpp file as : #include <cstdio> . How do I include the other library files? How do I add the graphics.h library? I\'m using Microsoft Visual Studio 6.0 Enterprise Edition and also Turbo C++ 3.0. 回答1: For a list of C standard C headers (stdio, stdlib, assert, ...),

What exactly do C include guards do?

旧街凉风 提交于 2019-11-26 10:02:21
问题 I have a question regarding include guards in C. I\'ve done a bit of reading but would appreciate a little bit of clarification. Let\'s say I have a header file \"header.h\" with a function definition. #ifndef HEADER_FILE #define HEADER_FILE int two(void){ return 2; } #endif This header file has an include guard. However, I\'m kind of confused as to what #define HEADER_FILE is actually doing. Let\'s say I were to forget the include guard, it would have been perfectly legal for me to

undefined reference when calling inline function

寵の児 提交于 2019-11-26 09:38:46
问题 I am getting a really odd error from GCC 4.8.1 with inline functions. I have two near-identical inline functions defined in header files ( debug.h and error.h ) in src/include/ , with the only difference being what they print - one prefixes DEBUG: to the message, and the other %s: error: %s (program name, error message). When defining the functions both inline, and compiling a debug build (so it sets the macro DEBUG=1 ), I get lots of undefined reference errors: src/main_debug.o gcc -osrc

Which headers in the C++ standard library are guaranteed to include another header?

左心房为你撑大大i 提交于 2019-11-26 09:36:50
问题 The C++ standard library headers may include each other in unspecified ways, so programmers generally shouldn\'t depend on one header including another. In a few cases, however, a header is guaranteed to include another header, or make available certain functions that would otherwise require inclusion of another header. What are those cases? 回答1: This answer ignores C headers - both the <meow.h> and <cmeow> ones. Of the C++ library headers (all references are to N4659): <initializer_list> is

Is #pragma once part of the C++11 standard?

独自空忆成欢 提交于 2019-11-26 09:19:34
问题 Traditionally, the standard and portable way to avoid multiple header inclusions in C++ was/is to use the #ifndef - #define - #endif pre-compiler directives scheme also called macro-guard scheme (see code snippet below). #ifndef MY_HEADER_HPP #define MY_HEADER_HPP ... #endif In most implementations/compilers (see picture below) however, there\'s a more \"elegant\" alternative that serves the same purpose as the macro-guard scheme called #pragma once. #pragma once has several advantages

Handling header files dependencies with cmake

半腔热情 提交于 2019-11-26 09:19:00
问题 I am using CMake on a small C++ project and so far it works great... with one twist :x When I change a header file, it typically requires recompiling a number of sources files (those which include it, directly or indirectly), however it seems that cmake only detects some of the source files to be recompiled, leading to a corrupted state. I can work around this by wiping out the project and rebuilding from scratch, but this circumvents the goal of using a make utility: only recompiling what is

Is the backslash acceptable in C and C++ #include directives?

安稳与你 提交于 2019-11-26 09:01:45
问题 There are two path separators in common use: the Unix forward-slash and the DOS backslash. Rest in peace, Classic Mac colon. If used in an #include directive, are they equal under the rules of the C++11, C++03, and C99 standards? 回答1: C99 says (§6.4.7/3): If the characters ', \, ", //, or /* occur in the sequence between the < and > delimiters, the behavior is undefined. Similarly, if the characters ', \, //, or /* occur in the sequence between the " delimiters, the behavior is undefined.