-1

I am reading this open source project:

I have two questions:

  1. I found the
#ifndef _RANGE_REQUEST_GENERATOR_H_
#define _RANGE_REQUEST_GENERATOR_H_
#endif

and I only find the _RANGE_REQUEST_GENERATOR_H_ in this .h file, other place not use it.

so, what's the usage of the macro definition?

  1. there use the namespace wrap the functions.
namespace slowhttptest {
    //functions
}

what's the purpose? why do not use std, is it better?

user7693832
  • 6,119
  • 19
  • 63
  • 114
  • For the first, look for the term "header include guard" - it's a technique to protect from problems that arise if a header file is included more than once (e.g. if a source file includes multiple headers, and more than one of them include this one). For the second, declaring or defining functions in namespace `std` is generally not allowed by the standard (only an implementation of the standard library can do that). – Peter Oct 04 '20 at 03:51
  • Also useful read: https://stackoverflow.com/questions/1263521/what-is-pragma-used-for – Unni Oct 04 '20 at 03:53
  • And Read https://stackoverflow.com/questions/47830610/what-are-the-dangers-of-using-pragma-once – srilakshmikanthanp Oct 04 '20 at 04:03

1 Answers1

1

Question #1

See Purpose of Header guards

Question #2

Consider the case where you are using libraries. And two libraries would both like to have a function named Push(). We could name them: LibraryFoo_Push(), and LibraryBar_Push(), or we could use namespaces. Namespaces have some additional benefits with lookups as well.

And see C++ When is it OK to extend the `std` namespace? for when you are allowed to add stuff to the std namespace.

Bill Lynch
  • 80,138
  • 16
  • 128
  • 173