header-files

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

南笙酒味 提交于 2019-11-27 05:00:50
问题 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. 回答1: 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

@ sign in C variable declaration

[亡魂溺海] 提交于 2019-11-27 04:32:32
问题 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

C Typedef - Incomplete Type

给你一囗甜甜゛ 提交于 2019-11-27 04:31:43
问题 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

How do I include the string header?

断了今生、忘了曾经 提交于 2019-11-27 04:29:36
问题 I'm trying to learn about string s, but different sources tell my to include different headers. Some say to use <string.h> , but others mention "apstring.h" . I was able to do some basic stuff with apstring , but I've been told the other one is more powerful. When I include <string.h> and try to declare some string variables, however, I get errors. What is the proper usage? 回答1: You want to include <string> and use std::string : #include <string> #include <iostream> int main() { std::string s

Including C headers inside a C++ program

佐手、 提交于 2019-11-27 03:56:47
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. For a list of C standard C headers (stdio, stdlib, assert, ...), prepend a c and remove the .h. For example stdio.h becomes cstdio. For other headers, use extern "C" { #include

Header for scanf_s function

陌路散爱 提交于 2019-11-27 03:41:21
问题 While answering this question I compiled the code on Ideone and got this error implicit declaration of function ‘scanf_s’ [-Wimplicit-function-declaration] Isn't stdio.h is the header for scanf_s ? 回答1: scanf_s is Microsoft-specific. Header is stdio.h but not in GCC. Used to Read formatted data from the standard input stream. These versions of scanf, scanf_s, _scanf_l, wscanf, _wscanf_l have security enhancements Where as Ideone uses GCC because of this only you got undefined reference to

How can a C++ header file include implementation?

久未见 提交于 2019-11-27 02:50:30
Ok, not a C/C++ expert by any means, but I thought the point of a header file was to declare the functions, then the C/CPP file was to define the implementation. However, reviewing some C++ code tonight, I found this in a class's header file... public: UInt32 GetNumberChannels() const { return _numberChannels; } // <-- Huh?? private: UInt32 _numberChannels; So why is there an implementation in a header? Does it have to do with the const keyword? Does that inline a class method? What exactly is the benefit/point of doing it this way vs. defining the implementation in the CPP file? Remy Lebeau

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

守給你的承諾、 提交于 2019-11-27 01:00:27
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++? Richard Corden 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. I felt the same way when I started writing C,

Handling header files dependencies with cmake

北城余情 提交于 2019-11-27 00:09:27
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 needed. Therefore, I suppose I am doing something wrong. My project is very simply organized: a top

Default member values best practice

佐手、 提交于 2019-11-27 00:01:15
问题 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? 回答1: If a class member is always