header-files

What does '_IO(…)' mean in C headers in Linux?

怎甘沉沦 提交于 2019-12-01 01:02:13
问题 I have a Linux standard header file e.g. /usr/src/linux-headers-3.2.0-35/include/linux/usbdevice_fs.h which contain define statements as follows: #define USBDEVFS_SUBMITURB32 _IOR('U', 10, struct usbdevfs_urb32) #define USBDEVFS_DISCARDURB _IO('U', 11) #define USBDEVFS_REAPURB _IOW('U', 12, void *) What does '_IOR', '_IO' and '_IOW' mean? What value is actually given e.g. to USBDEVFS_DISCARDURB ? 回答1: They define ioctl numbers, based on ioctl function and input parameters. The are defined in

C++ #ifndef for include files, why is all caps used for the header file?

柔情痞子 提交于 2019-12-01 00:05:47
I wonder why the name after the #ifndef directive is always all caps and don't seem to match the name of the actual header file? What are the rules surrounding this? I've been looking around the webs but, I haven't found any explanation for this. If my header file is called myheader.h would it then be ok to use: #ifndef MYHEADER If so, why? What are the rules? These are preprocessor symbols and have no such rules. (as long as they match the #defines in the headers) However, convention is to use all-caps for preprocessor symbols. Matteo Italia There's no "rule", there are just conventions. The

How to add .c and .h files to Atmel Studio 6?

佐手、 提交于 2019-11-30 22:58:48
I know there are a lot of questions on this topic, and I've looked through a fair number of them. However I am still having problems. I started writing a test program for a prototype PCB, and now that it's grown to nearly 1000 lines I'm trying to break it up into libraries that I can use for particular functions. I thought this would be very simple. Make .c and .h files for each library that I need. I.e. I would have OLED.h and OLED.c for functions that control an OLED display. Copy the appropriate functions/definitions into each file. Then copy these files into the solution in Atmel Studio. I

small functions defined in header files: inline or static?

本小妞迷上赌 提交于 2019-11-30 21:45:28
问题 I have a number of small functions which are defined in a .h file. It is a small project (now) and I want to avoid the pain of having declarations and definitions separate, because they change all the time. To avoid multiply-defined symbols, I can either have them static or inline . What should be preferred and why? I know it is in general bad practice to define functions in headers. You don't have to mention that in answers, this question is meant technically. 回答1: I'd use static inline ,

What could cause clang to not find the unordered_map header?

空扰寡人 提交于 2019-11-30 20:44:40
I'm trying to compile a program I found on the web using Clang++. The Makefile generates this command: clang++ -c -arch x86_64 -msse3 -std=c++11 -stdlib=libstdc++ -Wno-missing-field-initializers -Wno-missing-prototypes -Wreturn-type -Wno-non-virtual-dtor -Wno-exit-time-destructors -Wformat -Wmissing-braces -Wparentheses -Wno-switch -Wunused-function -Wunused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wno-empty-body -Wuninitialized -Wunknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wno-shorten-64-to-32 -Wenum

Is it a good idea to put all of your includes in one header file?

时光毁灭记忆、已成空白 提交于 2019-11-30 19:24:22
What is the best practice for C what you put into a C header file? Is it useful to put all the includes used for a program across multiple source files in one header file? What about includes that are used in practically every file (i.e. stdio.h)? No. It simply adds cruft and overhead. One of the biggest pains that you'll face as a maintainer is figuring out what headers don't need to be included and get rid of them. Whe you get to a list of 20+ headers, you start contemplating ugly things like brute forcing through it (removing one at a time and seeing if anything breaks). Be kind to people

#include <cmath> vs #include <math.h> in a C++ program [duplicate]

余生长醉 提交于 2019-11-30 18:57:01
This question already has an answer here: Should I include stddef.h or cstddef for size_t 5 answers Should I include <xxxx.h> or <cxxxx> in C++ programs? 2 answers What are the considerations for including the former rather than the latter in a C++ program? I always include math.h , stdlib.h and never cmath , cstdlib etc. I don't understand the reason the latter even exist, could someone please enlighten me? Prefer to include the <c ...> headers. They are C++ standard library headers. The <... .h> headers are headers defined by the C standard library: The C++ standard library also makes

Use the keyword class as a variable name in C++

与世无争的帅哥 提交于 2019-11-30 18:46:28
I am having trouble writing C++ code that uses a header file designed for a C file. In particular, the header file used a variable name called class: int BPY_class_validate(const char *class_type, PyObject *class, PyObject *base_class, BPY_class_attr_check* class_attrs, PyObject **py_class_attrs); This works in C as class isn't taken as a keyword, but in C++, class is. So is there anyway I can #include this header file into a c++ file, or am I out of luck? Thank you. try something like this: #define class class_variable // if class is only used in declarations, you can also do // #define class

C++ #ifndef for include files, why is all caps used for the header file?

最后都变了- 提交于 2019-11-30 18:10:36
问题 I wonder why the name after the #ifndef directive is always all caps and don't seem to match the name of the actual header file? What are the rules surrounding this? I've been looking around the webs but, I haven't found any explanation for this. If my header file is called myheader.h would it then be ok to use: #ifndef MYHEADER If so, why? What are the rules? 回答1: These are preprocessor symbols and have no such rules. (as long as they match the #defines in the headers) However, convention is

What's the benefit for a C source file include its own header file

谁说我不能喝 提交于 2019-11-30 17:48:35
I understand that if a source file need to reference functions from other file then it needs to include its header file, but I don't understand why the source file include its own header file. Content in header file is simply being copied and pasted into the source file as function declarations in per-processing time. For source file who include its own header file, such "declaration" doesn't seem necessary to me, in fact, project still compile and link no problem after remove the header from it's source file, so what's the reason for source file include its own header? The main benefit is