0

In climit

// climits standard header (core)

// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#pragma once
#ifndef _CLIMITS_
#define _CLIMITS_
#include <yvals_core.h>
#if _STL_COMPILER_PREPROCESSOR

#include <limits.h>

#endif // _STL_COMPILER_PREPROCESSOR
#endif // _CLIMITS_

Why there is #ifndef _CLIMITS_ if already use #pragma once ?

6
  • Looks like a case of belt and braces. Commented Jul 28, 2021 at 20:50
  • #pragma once runs into issues if it's difficult for the preprocessor to tell whether two files are "the same" file or not. Hence doing it both ways. Commented Jul 28, 2021 at 20:53
  • And, in case it isn't clear, this header is part of the C++ implementation, so the use of _CLIMITS_ as the name of the include guard is okay. That name (beginning with an underscore followed by a capital letter) is reserved for use by the implementation. Don't take this as an example of how you should write your own include guards. Commented Jul 28, 2021 at 21:07
  • Interesting that Microsoft's header files do this when their own documentation says, "There's no advantage to use of both the include guard idiom and #pragma once in the same file." Commented Jul 28, 2021 at 21:07
  • @FredLarson Microsoft are the kings of backwards compatibility. It's possible that they want to make sure the header file still works on some 25-year old compiler that didn't have #pragma once. Or, for anti-trust reasons, they have to make it work on other compilers that never had it. Commented Jul 28, 2021 at 21:43

0

Browse other questions tagged or ask your own question.