Questions tagged [headers]

76 questions
129
votes
8 answers

Is it better to document functions in the header file or the source file?

In languages that distinguish between a "source" and "header" file (mainly C and C++), is it better to document functions in the header file: (pilfered from CCAN) /** * time_now - return the current time * * Example: * printf("Now is %lu…
Joey Adams
  • 5,535
  • 3
  • 30
  • 34
93
votes
5 answers

Why do we need to put private members in headers?

Private variables are a way to hide complexity and implementation details to the user of a class. This is a rather nice feature. But I do not understand why in c++ we need to put them in the header of a class. I see two annoying downsides to…
Simon Bergot
  • 7,930
  • 3
  • 35
  • 54
92
votes
5 answers

Best practices for making header file?

What things should absolutely always/never be included in a header file? Functions: what must go in the header file and what mustn't Constants: Is it good practice to define lot of constants in a header file? Any other good practices for C header…
Moshe Magnes
  • 1,071
  • 1
  • 8
  • 6
57
votes
8 answers

Is it good practice to rely on headers being included transitively?

I'm cleaning up the includes in a C++ project I'm working on, and I keep wondering whether or not I should explicitly include all headers used directly in a particular file, or whether I should only include the bare minimum. Here's an example,…
futlib
  • 2,107
  • 3
  • 21
  • 26
53
votes
7 answers

How can I prevent header hell?

We are starting a new project, from scratch. About eight developers, a dozen or so subsystems, each with four or five source files. What can we do to prevent “header hell”, AKA “spaghetti headers”? One header per source file? Plus one per…
48
votes
4 answers

Why is #include bad?

I was reading another thread where a guy asked about C++ books for beginners, and one of the programmers answering wrote this: Some warnings: avoid all books that present an "hello world" stating with #include I opened my C++ book…
Daniel Scocco
  • 5,832
  • 9
  • 39
  • 47
48
votes
3 answers

Copyright statements in source code

Ever since I started programming I've seen a header at the top of most code files indicating some sort of copyright: e.g. /* Copyright (c) 1998 Innotech */ or /* Copyright (c) 1998-2008 Innotech */ Conceptually I get the idea... depending on your…
scunliffe
  • 684
  • 1
  • 6
  • 14
42
votes
6 answers

Why can you have the method definition inside the header file in C++ when in C you cannot?

In C, you cannot have the function definition/implementation inside the header file. However, in C++ you can have a full method implementation inside the header file. Why is the behaviour different?
Joshua Partogi
  • 3,845
  • 11
  • 34
  • 43
38
votes
1 answer

Where to place an API key: a custom HTTP header VS the Authorization header with a custom scheme

I'm designing a REST API using authorization/authentication via an API Key. I tried to figure out what is the best place for it and found out that many people suggest using a custom HTTP header such as ProjectName-Api-Key, eg: ProjectName-Api-Key:…
RomanG
  • 491
  • 1
  • 4
  • 6
22
votes
7 answers

Why do we need to include the .h while everything works when including only the .cpp file?

Why do we need to include both the .h and .cpp files while we can make it work solely by including the .cpp file? For example: creating a file.h containing declarations, then creating a file.cpp containing definitions and including both in…
reaffer
  • 355
  • 1
  • 2
  • 5
15
votes
4 answers

Why do we need to write a header file?

Before you whip out your snarky comments, I know -- this is a nooby question. This is my first time using a C based language. I'm an undergrad student learning Objective C for a computer science course on mobile development. I know that, in an…
Hartley Brody
  • 344
  • 1
  • 2
  • 8
13
votes
3 answers

Is it safe to transmit access tokens via HTTP headers?

It's the first RESTful web service and I am concerned about security issues. Is it safe to transmit my access token via HTTP headers? For example: POST /v1/i/resource HTTP/1.1 Content-Type: application/x-www-form-urlencoded Api-key:…
ahmedsaber111
  • 233
  • 1
  • 2
  • 5
12
votes
4 answers

Ways to organize interface and implementation in C++

I've seen that there are several different paradigms in C++ concerning what goes into the header file and what to the cpp file. AFAIK, most people, especially those from a C background, do: foo.h class foo { private: int mem; int bar(); …
Felix Dombek
  • 2,109
  • 1
  • 16
  • 24
11
votes
2 answers

Updating copyright headers each new year just because Jan 1st has passed?

I've seen some projects that - with each new year - start to change all files in their source-tree to update the copyright year. Isn't this just pushing hot air on a level of magnitude? AFAIK: Copyright year is based on relevant changes of a work…
hakre
  • 1,165
  • 12
  • 17
11
votes
2 answers

Custom use of Authorization header in a REST API

I'm building a REST api where clients are authenticated using client certificates. A client in this case is not an individual user, but some sort of a presentation layer. Users are authenticated using a custom approach and it's the responsibility of…
Matsen75
  • 227
  • 1
  • 2
  • 8
1
2 3 4 5 6