header-files

Is an #include before #ifdef/#define Include-Guard okay?

痞子三分冷 提交于 2019-12-22 03:59:13
问题 I always placed my #include after the #ifdef / #define Include-Guard. Now the refactor mechanism of my IDE (Qt Creator) put it before the Include-Guard e.g. #include "AnotherHeader.h" #ifndef MYHEADER_H #define MYHEADER_H Can this cause any problems or can I leave it this way? 回答1: If the header in question has include guards itself, you won't run into problems. Putting it inside the include guards may still speed up compilation. Something the compiler does not see takes less time to compile,

Why /usr/include/linux/stddef.h is empty?

烈酒焚心 提交于 2019-12-22 03:47:02
问题 This header file shall define NULL or size_t and other macros, but I find that /usr/include/linux/stddef.h is empty? Why? 回答1: The actual location of the headers is implementation defined. What you look at is not the typical <stddef.h> included by gcc. You can find out exactly where it's located on your system with: gcc -E - <<<'#include<stddef.h>' | grep stddef.h which is equivalent to including the header <stddef.h> in an empty C file and running gcc -E on it. The headers in /usr/include

correct way to include .cpp and .h files in an Arduino sketch

*爱你&永不变心* 提交于 2019-12-22 02:04:07
问题 First, the problem: main sketch file: char foo; // required to clean up some other problems #include <Arduino.h> // tried it in desperation, no help #include "a.h" void setup(){ Serial.begin(9600); Serial.println("\nTest begins"); for (int num = -1; num < 1; num++){ Serial.print(num); if (isNegative(num)){ Serial.println(" is negative"); } else { Serial.println(" is NOT negative"); } } } void loop(){} // a.h #ifndef H_A #define H_A boolean isNegative(int x); // Err#1 int anotherOdity();

osx sys/io.h not found

纵然是瞬间 提交于 2019-12-21 20:46:19
问题 I'd like to compile a c programm developed for linux using cc under os x. It includes the header sys/io.h. When compiling I get the error that this file could not be found? Isn't there any sys/io.h header file under os x? Any help would be really appreciated! Thanks! 回答1: Include <sys/uio.h> instead. or why not both? #ifdef __APPLE__ #include <sys/uio.h> #else #include <sys/io.h> #endif In case of Apple OS (OSX/iOS) the code will know compile with <sys/uio.h> 回答2: What bibor has written is

headerfile not found

烂漫一生 提交于 2019-12-21 20:36:09
问题 I am working on a iphone app and everything went fine untill I tried to import NSFetchedResultsController.h. when I was typing this Xcode completed it for me. But now it gives the error: NSFetchedResultsController.h file not found. I included it like this: #import "NSFetchedResultsController.h" I looked all over the internet for the answer to this, but nothing works. (and a few things need Xcode 4.3 to work). I am using Xcode 4.2 on Snow Leopard. 回答1: In fact you really don't need to import

Is programming against interfaces in Java the same concept as using header files in C/C++?

我的梦境 提交于 2019-12-21 07:55:16
问题 The java code I'm working on at the moment has often a structure like file Controller.java: interface Controller {...} file ControllerImpl.java: class ControllerImpl implements Controller {...} But for every interface there is only one implementation. Isn't that the same as using header files in C/C++ where I have the code split into files like Controller.hpp Controller.cpp From what I know, header files in C/C++ have been introduced to help the compiler, which is not necessary anymore in

Why is const unnecessary in function declarations in header files for parameters passed by value?

僤鯓⒐⒋嵵緔 提交于 2019-12-21 05:07:06
问题 I was recently reading about the usage of const keyword as function arguments in C and the way to use that has been mentioned in When and for what purposes should the const keyword be used in C for variables and been accepted as correct answer. In this post, one point mentions that Never use const in a function prototype for a parameter passed by value. It has no meaning and is hence just 'noise'. I used this way and it works for me but I am not sure why that is a noise for parameters passed

c++ static array declared in h file gives warning 'defined but not used'

柔情痞子 提交于 2019-12-21 04:27:17
问题 I'm curious about the following. I have a simple C array declared in a header file like this: static int userCardsIndexes[INITIAL_CARDS_NUMBER] = {0, 1, 8, 9, 16, 17}; it gives me a bunch of the warnings: : 'userCardsIndexes' defined but not used despite i include this file into my cpp files and use this variable. The second thing that i don't understand about it is when i add const specifier like this: static const int userCardsIndexes[INITIAL_CARDS_NUMBER] = {0, 1, 8, 9, 16, 17}; the

XCode 4 Relative #include paths in search?

邮差的信 提交于 2019-12-21 04:07:03
问题 I'm trying to port over a project I initially wrote in Windows to OS X and am having some difficulty with the header search paths. I've used user search paths to include by source folder "project/src/core/" Under core, I have, for example: "projects/src/core/sys/sys_sdl.h" which tries to include "projects/src/core/render/opengl_render.h" with the directive: #include "render/opengl_render.h" I've tried tons of different options, but I can't get seem to get Xcode to find the file unless I

Including header file from static library

∥☆過路亽.° 提交于 2019-12-21 03:32:57
问题 I am making a test setup of a C static library and program. The library code, located in a subdirectory 'foo' of my project, contains the following files: foo/foo.c: #include <stdio.h> void foo(void) { printf("something"); } foo/foo.h: #ifndef foo_h__ #define foo_h__ extern void foo(void); #endif My progam code is as follows: test.c: #include "foo.h" int main() { foo(); return 0; } I have a build script, called 'build', which contains the following: build: #!/bin/bash gcc -c -Wall -Werror foo