microlisp 0.1.0
A small Scheme-subset interpreter in modern C.
Loading...
Searching...
No Matches
export.h
Go to the documentation of this file.
1/*
2 * SPDX-License-Identifier: MIT
3 *
4 * Symbol-visibility macros and small attribute helpers. Public declarations
5 * carry MICROLISP_API so shared-library builds can hide everything else with
6 * -fvisibility=hidden. The attribute helpers (MICROLISP_NODISCARD,
7 * MICROLISP_NORETURN, MICROLISP_PRINTF) are also exposed here because callers
8 * benefit from the compile-time enforcement they provide.
9 */
10#ifndef MICROLISP_EXPORT_H
11#define MICROLISP_EXPORT_H
12
13/* -- MICROLISP_API: public-symbol visibility -------------------------------- */
14#if defined(_WIN32) || defined(__CYGWIN__)
15#if defined(MICROLISP_BUILD_SHARED)
16#define MICROLISP_API __declspec(dllexport)
17#elif defined(MICROLISP_USE_SHARED)
18#define MICROLISP_API __declspec(dllimport)
19#else
20#define MICROLISP_API
21#endif
22#else
23#if defined(MICROLISP_BUILD_SHARED) && (defined(__GNUC__) || defined(__clang__))
24#define MICROLISP_API __attribute__((visibility("default")))
25#else
26#define MICROLISP_API
27#endif
28#endif
29
30/* -- MICROLISP_NODISCARD: warn if the return value is ignored --------------- */
31#if defined(__GNUC__) || defined(__clang__)
32#define MICROLISP_NODISCARD __attribute__((warn_unused_result))
33#elif defined(_MSC_VER)
34#define MICROLISP_NODISCARD _Check_return_
35#else
36#define MICROLISP_NODISCARD
37#endif
38
39/* -- MICROLISP_NORETURN: function doesn't return ---------------------------- */
40#if defined(__GNUC__) || defined(__clang__)
41#define MICROLISP_NORETURN __attribute__((noreturn))
42#elif defined(_MSC_VER)
43#define MICROLISP_NORETURN __declspec(noreturn)
44#else
45#define MICROLISP_NORETURN
46#endif
47
48/* -- MICROLISP_PRINTF: type-check printf-style args ------------------------- */
49#if defined(__GNUC__) || defined(__clang__)
50/* On MinGW the `printf` archetype maps to MSVCRT's printf, which doesn't
51 * support %zu / %lld and friends. We use gnu_printf there so the format
52 * checker matches the ANSI-stdio path the library actually links against. */
53#if defined(__MINGW32__) || defined(__MINGW64__)
54#define MICROLISP_PRINTF(fmt_idx, vararg_idx) \
55 __attribute__((format(gnu_printf, fmt_idx, vararg_idx)))
56#else
57#define MICROLISP_PRINTF(fmt_idx, vararg_idx) __attribute__((format(printf, fmt_idx, vararg_idx)))
58#endif
59#else
60#define MICROLISP_PRINTF(fmt_idx, vararg_idx)
61#endif
62
63#endif /* MICROLISP_EXPORT_H */