header-files

Why do both “std::printf” and “printf” compile when using <cstdio> rather than <stdio.h> in C++? [duplicate]

限于喜欢 提交于 2019-11-28 04:50:24
问题 This question already has answers here : When using C headers in C++, should we use functions from std:: or the global namespace? (8 answers) Closed last year . To my knowledge, headers of the form cxyz are identical to xyz.h with the only difference being that cxyz places all of the contents of xyz.h under the namespace std . Why is it that the following programs both compile on GCC 4.9 and clang 6.0? #include <cstdio> int main() { printf("Testing..."); return 0; } and the second program:

Default member values best practice

醉酒当歌 提交于 2019-11-28 03:08:06
Is it good practice when writing C++11 code to set default values for class members in the header file of the class? Or is it better to do this in the constructor of the class? EDIT: I mean: foo.h : #include <string> using std::string; class Foo{ private: string greet = "hello"; public: Foo(); }; VS foo.cpp (of course with the necessary header file, but without the in-class initialization): Foo::Foo(){ greet = "hello"; } Which one is better and why? If a class member is always initialized with the same initial value, then you should make the initializer inline, so as to avoid duplication. If

How can I find the header files of the C programming language in Linux?

泄露秘密 提交于 2019-11-28 03:02:05
When I write C programs in Linux, and then compile them using gcc, I am always curious about where those header files are. For example, where stdio.h is. More generally, where is stdbool.h ? What I want to know is not only where it is, but also how to get those places, for example, using shell command or using the C programming language. gcc -H ... will print the full path of every include file as a side-effect of regular compilation. Use -fsyntax-only in addition to get it not to create any output (it will still tell you if your program has errors). Example (Linux, gcc-4.7): $ cat > test.c

C++ Circular Dependency in Header Files

好久不见. 提交于 2019-11-28 02:20:05
Is it possible to avoid circular dependency in the following header files without turning data member b1 in class A to a pointer/reference, and without relaxing the inline function requirement in class B ? A.h: #ifndef A_H #define A_H #include <B.h> // Required, as data member b1 is not a pointer/reference class A { public: B b1; // I want to keep this as as it is. int m_a; }; #endif B.h: #ifndef B_H #define B_H #include <A.h> // Required, as f() calls a member function of class A class B { public: int f(A &a){return a.m_a;} // I want this to be an inline function. }; #endif ...and let's say

“XXX-Swift.h” file not found in test project

元气小坏坏 提交于 2019-11-28 01:10:34
问题 I'm trying to call a method of a NSObject subclass I have in the let's say "main" project within a method of a XCTestCase subclass in the test project. The NSObject subclass of the main project imports the "XXX-Swift.h" header file (I'm mixing Swift and Objective-C code). All works fine when I run the main project, but when I run the tests calling an object of that subclass, I get an error saying that the Swift header file in the import is not found. I guess I'm missing some settings in the

How do I run the preprocessor on local headers only?

旧街凉风 提交于 2019-11-27 23:30:33
I want the preprocessor to read in the includes of local headers, but ignore the includes of system headers. To put it another way, how do I get the preprocessor to skip over preprocessing directives of the form: #include <h-char-sequence> new-line but still process directives of the form: #include "q-char-sequence" new-line As a code example, observe the following file: #include <iostream> //system #include "class_a.hpp" //local #include <string> //system #include "class_b.hpp" //local int main() {} how can I get the output of the preprocessor to be: #include <iostream> class A{}; #include

endian.h not found on mac osx

余生长醉 提交于 2019-11-27 22:00:26
I meet some trouble when I compile some C code on my mac which give me this error : fatal error: 'endian.h' file not found I did some google search about this problem.It seems like mac os x does not have header files like "endian.h", we have to create this file manually. Then, I found this http://www.opensource.apple.com/source/CarbonHeaders/CarbonHeaders-18.1/Endian.h which might be the file I am looking for but not sure. But more troubles are coming.. where should I put this file? The file /usr/include does not exist. These are the folders in my /usr directory: X11 bin libexec share X11R6

@ sign in C variable declaration

不问归期 提交于 2019-11-27 21:55:09
I found this header file for PIC microcontrollers by the name of pic1250.h and I'm unable to get the hang of some syntax used in it. The source for the file is: /* * Header file for the Microchip * PIC 12c508 chip * PIC 12c509 chip * Baseline Microcontrollers */ static volatile unsigned char RTCC @ 0x01; static volatile unsigned char TMR0 @ 0x01; static volatile unsigned char PCL @ 0x02; static volatile unsigned char STATUS @ 0x03; static unsigned char FSR @ 0x04; static volatile unsigned char OSCCAL @ 0x05; static volatile unsigned char GPIO @ 0x06; static unsigned char control OPTION @ 0x00;

C Typedef - Incomplete Type

若如初见. 提交于 2019-11-27 21:37:40
So, out of the blue, the compiler decides to spit this in face: "field customer has incomplete type". Here's the relevant snippets of code: customer.c #include <stdlib.h> #include <string.h> #include "customer.h" struct CustomerStruct; typedef struct CustomerStruct { char id[8]; char name[30]; char surname[30]; char address[100]; } Customer ; /* Functions that deal with this struct here */ customer.h A header file for customer.h #include <stdlib.h> #include <string.h> #ifndef CUSTOMER_H #define CUSTOMER_H typedef struct CustomerStruct Customer; /* Function prototypes here */ #endif This is

Including header files in C/C++ more than once [duplicate]

我与影子孤独终老i 提交于 2019-11-27 19:58:20
This question already has an answer here: Is there any situation where you wouldn't want include guards? 6 answers Is it ever useful to include a header file more than once in C or C++? If the mechanism is never used, why would the compiler ever worry about including a file twice; if it really were useless, wouldn't it be more convenient if newer compilers made sure every header is included only once? Edit: I understand that there are standard ways of doing things like include guards and pragma once , but why should you have to specify even that? Shouldn't it be the default behavior of the