Skip to content

Commit

Permalink
Moving bool include hacks into a dedicated header file.
Browse files Browse the repository at this point in the history
This was inspired (in the initial commit [1]) by a header from
`msgpack` [2] (and also some help from StackOverflow [3] about
`_MSC_VER` and Matthew Brett's pydagogue doc [4]).

The "last" modification (in [5]) diverges from the original ([2])
by using `char` instead of `int` as the `bool` alias on Windows.
This is so that we can remain true to the binary interface.

[1]: 833643f
[2]: https://github.com/msgpack/msgpack-c/blob/b02c6beb4dfc28b9651ac78e583d2273aef679a7/include/msgpack/sysdep.h#L180-L195
[3]: https://stackoverflow.com/a/5850405/1068170
[4]: http://matthew-brett.github.io/pydagogue/python_msvc.html
[5]: 6fb9da2
  • Loading branch information
dhermes committed Oct 16, 2017
1 parent b5ed586 commit 5577178
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 60 deletions.
44 changes: 44 additions & 0 deletions src/bezier/include/bezier/bool_patch.h
@@ -0,0 +1,44 @@
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef BEZIER_BOOL_PATCH_H
#define BEZIER_BOOL_PATCH_H

#if defined (__cplusplus)
extern "C" {
#elif !defined (_MSC_VER)
#include <stdbool.h>
#endif

#if !defined (__cplusplus) && defined (_MSC_VER)
# if !defined (FALSE)
# define FALSE (0)
# endif
# if !defined (TRUE)
# define TRUE (!FALSE)
# endif
# if _MSC_VER >= 1800
# include <stdbool.h>
# else
// NOTE: We must use `char` because it is 1 byte, as `bool` is
// in C99 and later (which is what `gfortran` uses).
# define bool char
# define true TRUE
# define false FALSE
# endif
#endif

#if defined (__cplusplus)
}
#endif

#endif /* BEZIER_BOOL_PATCH_H */
22 changes: 2 additions & 20 deletions src/bezier/include/bezier/curve.h
Expand Up @@ -13,28 +13,10 @@
#ifndef BEZIER_CURVE_H
#define BEZIER_CURVE_H

#include "bezier/bool_patch.h"

#if defined (__cplusplus)
extern "C" {
#elif !defined (_MSC_VER)
#include <stdbool.h>
#endif

#if !defined (__cplusplus) && defined (_MSC_VER)
# if !defined (FALSE)
# define FALSE (0)
# endif
# if !defined (TRUE)
# define TRUE (!FALSE)
# endif
# if _MSC_VER >= 1800
# include <stdbool.h>
# else
// NOTE: We must use `char` because it is 1 byte, as `bool` is
// in C99 and later (which is what `gfortran` uses).
# define bool char
# define true TRUE
# define false FALSE
# endif
#endif

void evaluate_curve_barycentric(
Expand Down
22 changes: 2 additions & 20 deletions src/bezier/include/bezier/curve_intersection.h
Expand Up @@ -13,28 +13,10 @@
#ifndef BEZIER_CURVE_INTERSECTION_H
#define BEZIER_CURVE_INTERSECTION_H

#include "bezier/bool_patch.h"

#if defined (__cplusplus)
extern "C" {
#elif !defined (_MSC_VER)
#include <stdbool.h>
#endif

#if !defined (__cplusplus) && defined (_MSC_VER)
# if !defined (FALSE)
# define FALSE (0)
# endif
# if !defined (TRUE)
# define TRUE (!FALSE)
# endif
# if _MSC_VER >= 1800
# include <stdbool.h>
# else
// NOTE: We must use `char` because it is 1 byte, as `bool` is
// in C99 and later (which is what `gfortran` uses).
# define bool char
# define true TRUE
# define false FALSE
# endif
#endif

enum BoxIntersectionType {
Expand Down
22 changes: 2 additions & 20 deletions src/bezier/include/bezier/helpers.h
Expand Up @@ -13,28 +13,10 @@
#ifndef BEZIER_HELPERS_H
#define BEZIER_HELPERS_H

#include "bezier/bool_patch.h"

#if defined (__cplusplus)
extern "C" {
#elif !defined (_MSC_VER)
#include <stdbool.h>
#endif

#if !defined (__cplusplus) && defined (_MSC_VER)
# if !defined (FALSE)
# define FALSE (0)
# endif
# if !defined (TRUE)
# define TRUE (!FALSE)
# endif
# if _MSC_VER >= 1800
# include <stdbool.h>
# else
// NOTE: We must use `char` because it is 1 byte, as `bool` is
// in C99 and later (which is what `gfortran` uses).
# define bool char
# define true TRUE
# define false FALSE
# endif
#endif

void cross_product(double *vec0, double *vec1, double *result);
Expand Down

0 comments on commit 5577178

Please sign in to comment.