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 ?

Streamer
  • 25
  • 4
  • Looks like a case of [belt and braces](https://dictionary.cambridge.org/dictionary/english/belt-and-braces). – Fred Larson Jul 28 '21 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. – Nathan Pierson Jul 28 '21 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. – Pete Becker Jul 28 '21 at 21:07
  • Interesting that Microsoft's header files do this when [their own documentation](https://learn.microsoft.com/en-us/cpp/preprocessor/once?redirectedfrom=MSDN&view=msvc-160) says, "There's no advantage to use of both the include guard idiom and #pragma once in the same file." – Fred Larson Jul 28 '21 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. – Mark Ransom Jul 28 '21 at 21:43
  • @MarkRansom: I guess. But then those would be advantages, wouldn't they? 8v) – Fred Larson Jul 28 '21 at 21:48

0 Answers0