header-files

Where to document functions in C or C++? [closed]

别说谁变了你拦得住时间么 提交于 2019-11-27 19:16:48
I have a C program with multiple files, so I have, for example, stuff.c which implements a few functions, and stuff.h with the function prototypes. How should I go about documenting the functions in comments? Should I have all the docs in the header file, all the docs in the .c file, or duplicate the docs for both? I like the latter approach, but then I run into problems where I'll update the docs on one of them and not the other (usually the one where I make the first modification, i.e. if I modify the header file first, then its comments will reflect that, but if I update the implementation,

Best practices for use of C++ header files [closed]

泄露秘密 提交于 2019-11-27 18:34:56
I have the following doubts on header files usage. 1 - Include guards placing after comments /* Copyright Note and licence information (multiple lines) */ #ifndef FOO_H #define FOO_H // Header file contents #endif Herb Sutter says in his "C++ coding standards" book that code like the above is problematic. He is saying the "#ifndef" statements should appear in the first line of the header file. I haven't felt this as convincing. Is this followed by you guys/gals in header files? 2 - Using namespaces in header files #ifndef FOO_H #define FOO_H namespace FooNameSpace{ // Header file contents }

Header file inclusion static analysis tools?

*爱你&永不变心* 提交于 2019-11-27 18:33:08
A colleague recently revealed to me that a single source file of ours includes over 3,400 headers during compile time. We have over 1,000 translation units that get compiled in a build, resulting in a huge performance penalty over headers that surely aren't all used. Are there any static analysis tools that would be able to shed light on the trees in such a forest, specifically giving us the ability to decide which ones we should work on paring out? UPDATE Found some interesting information on the cost of including a header file (and the types of include guards to optimize its inclusion) here

Why is there no multiple definition error when you define a class in a header file?

你说的曾经没有我的故事 提交于 2019-11-27 18:14:44
问题 I'm not sure if I asked the question correctly, but let me explain. First, I read this article that explains the difference between declarations and definitions: http://www.cprogramming.com/declare_vs_define.html Second, I know from previous research that it is bad practice to define variables and functions in a header file, because during the linking phase you might have multiple definitions for the same name which will throw an error. However, how come this doesn't happen for classes?

Writing function definition in header files in C++

我与影子孤独终老i 提交于 2019-11-27 17:09:46
I have a class which has many small functions. By small functions, I mean functions that doesn't do any processing but just return a literal value. Something like: string Foo::method() const{ return "A"; } I have created a header file "Foo.h" and source file "Foo.cpp". But since the function is very small, I am thinking about putting it in the header file itself. I have the following questions: Is there any performance or other issues if I put these function definition in header file? I will have many functions like this. My understanding is when the compilation is done, compiler will expand

What is WINVER?

不问归期 提交于 2019-11-27 14:18:14
I was looking at some code and they had this line: #define WINVER 0x0501 in stdafx.h file? Why do you need to define WINVER ? How does it affect your code? Can someone please explain? Reed Copsey WINVER determines the minimum platform SDK required to build your application, which in turn will determine at compile time which routines are found by the headers. You can use this to verify, at compile time, that your application will work on Windows 2000 (0x0500), for example, or on Windows XP (0x0501). MSDN's page on Modifying WINVER and _WIN32_WINNT goes into this in more detail. WINVER defines

Header file included only once in entire program?

十年热恋 提交于 2019-11-27 13:31:42
I know this is a common question but I still can't fully get my head around it. In a C or C++ program generated from multiple different source and header files, will each header file be only included once in the entire code when the header guards are used? Someone told me previously that a header file (with include guards) will get included only once in one translation unit but multiple times in the entire code. Is this true? If it gets included only once throughout the entire code, when one file wishes to include it and the preprocessor detects that it has already been included, how does that

When are header-only libraries acceptable?

怎甘沉沦 提交于 2019-11-27 12:07:32
问题 Personally, I quite like header-only libraries, but there are claims they cause code bloat due to over-inlining (as well as the other obvious problem of longer compile times). I was wondering, how much truth is there to these claims (the one about bloat)? Furthermore, are the costs 'justified'? (Obviously there are unavoidable cases such as when it's a library implemented purely or mostly with templates, however I'm more interested in the case where there's actually a choice available.) I

How to make Xcode find file FacebookSDK.h?

百般思念 提交于 2019-11-27 12:01:11
It says "FacebookSDK/FacebookSDK.h file not found" Yet I can jump-to-definition on the #import and it takes me to the file. And once I added the #import it now knows what FBFriendPickerDelegate is and it now doesn't have an error on that line. I have the facebookSDK.framework in my project and in the right folder. It's SDK 3.1. I tried adding search paths to /FacebookSDK and /FacebookSDK.framework and /FacebookSDK/Versions/A/Headers etc. I also tried #import "FacebookSDK.framework/Versions/A/Headers/FacebookSDK.h" and it still says it can't find it. I also tried clean and restarting. I have

Eclipse CDT: Unresolved inclusion of stl header

て烟熏妆下的殇ゞ 提交于 2019-11-27 11:58:47
I'm trying to use Eclipse to edit sources, compiled under C++ Builder, but stuck with Unresolved inclusion problem. For example, code like: #include <vector> Gives Unresolved inclusion: <vector> error in Eclipse IDE. C++ Builder indeed has no vector file, instead it has vector.h which is used by compiler. Eclipse IDE gives no error if I write #include <vector.h> How do I tell Eclipse to use vector.h when it sees #include <vector> ? This allowed me to avoid Eclipse "Unresolved inclusion" error. In my case I had to find the location of the C++ vector header on my computer (which is a Mac): find