When working with integer constants, it is convenient to use #define
macros for the constants, as opposed to a variable of constant type.
This patch adds a '#define CONSTANT (value)' definition to the
generated header files. The name of the constant is in
SCREAMING_SNAKE_CASE, converted from the regular camelCase.
Signed-off-by: Curt Brune <curt@enfabrica.net>
This patch adds the 'const' keyword to constant definitions generated
by the compiler. Previously the compiler generated constants like
this:
foo.h
======
extern int foo;
foo.c
======
int foo = 5;
With this patch, the generated code looks like:
foo.h
======
extern const int foo;
foo.c
======
const int foo = 5;
Signed-off-by: Curt Brune <curt@enfabrica.net>
schema files.
Some schema files (eg. those that only decalare annotations) do not actually
result in any generated C code. They do not need to have a corresponding
include directive for C files generated from schemas that include them. This
introduces a "donotinclude" annotation that takes the Cap'n Proto ID (a
UInt64) of any such files and skips generating the include directive for them.
ANSI C makes no guarantee about the size of an enum, only that it will be the
minimum required integer type that can hold all the given values. Treating
enums as interchangeable with uint16_t data caused undefined behavoiur on
platforms where enums were always at least 32 bits.
With some toolchains, compilation of str.c produced the following error:
compiler/str.h:56:50: error: unknown type name ‘va_list’
int str_vaddf(struct str *v, const char *format, va_list ap) ATTR(2,0);
^~~~~~~
One toolchain had the following in its stdarg.h:
"We deliberately do not define va_list when called from
stdio.h, because ANSI C says that stdio.h is not supposed to
define va_list."
str.c includes stdio.h, but none of the prior includes result in the
inclusion of stdarg.h. Therefore, explicitly include it in str.h to fix
the issue on toolchains following this ANSI C rule.
Signed-off-by: Joel Carlson <JoelsonCarl@gmail.com>
(Marker merge -- cherry-picked the size format; the align one is
superseded and the gtest ones collide with gtest's upstream
recommendations [only Gentoo has gtest as a package].)
The case of creating capnp lists of size 0 didn't consider lists of
composite elements (structs), which requires the addition of list
element information.
This commit removes the case of size 0 when creating the list in order
to enable the creation of 0 sized lists of any element type (struct).