Add example of separating inline & function code

This commit is contained in:
Patrick Pelissier authored and Patrick Pelissier committed 2023-06-11 23:32:02 +02:00
1 parent 17ded6fcc8
commit 53af2aae68
7 files changed
+85 -1

No files matched your search

+11 -1
View File
@@ -21,7 +21,7 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
CC=cc -std=c99
CFLAGS=-Wall -W -pedantic -Wshadow -Wpointer-arith -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wswitch-default -Wswitch-enum -Wcast-align -Wpointer-arith -Wbad-function-cast -Wstrict-overflow=5 -Wstrict-prototypes -Winline -Wundef -Wnested-externs -Wcast-qual -Wshadow -Wunreachable-code -Wlogical-op -Wstrict-aliasing=2 -Wredundant-decls -Wold-style-definition -Wno-unused-function -g
CFLAGS=-Wall -W -pedantic -Wshadow -Wpointer-arith -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wswitch-default -Wswitch-enum -Wcast-align -Wpointer-arith -Wbad-function-cast -Wstrict-overflow=5 -Wstrict-prototypes -Wundef -Wnested-externs -Wcast-qual -Wshadow -Wunreachable-code -Wlogical-op -Wstrict-aliasing=2 -Wredundant-decls -Wold-style-definition -Wno-unused-function -g
GMP_DIR=
MPFR_DIR=$(GMP_DIR)
CPPFLAGS=-I..
@@ -33,9 +33,19 @@ RM=rm -f
.c.exe:
$(CC) $(CFLAGS) $(CPPFLAGS) $< -o $@ `cat config` $(LDFLAGS)
.c.o:
$(CC) $(CFLAGS) $(CPPFLAGS) -O2 -ffunction-sections -fdata-sections -DNDEBUG -g $< -c -o $@ `cat config` $(LDFLAGS)
all: config
$(MAKE) `ls ex-*.c|sed -e 's/\.c/\.exe/g'`
if test "$(CC)" = "cc -std=c99" ; then $(MAKE) `ls ex11-*.c|sed -e 's/\.c/\.exe/g'` CC="cc -std=c11" ; fi
$(MAKE) exm.exe
exm.exe: exm-lib.o exm-main.o
$(CC) -Wl,--gc-sections -g $^ -o $@
exn.exe: exn-lib.o exn-main.o
$(CC) -Wl,--gc-sections -g $^ -o $@
config:
printf "#include <gmp.h>\nint main(void){mpz_t z; mpz_init(z); return 0;}\n" > config-test.c
+14
View File
@@ -0,0 +1,14 @@
#ifndef MY_HEADER
#define MY_HEADER
// Request M*LIB to not inline functions if not the library source
#ifndef M_USE_EXTERN_DEF
#define M_USE_EXTERN_DECL
#endif
#include "m-string.h"
#include "m-array.h"
ARRAY_DEF(array_str, string_t)
#endif
+4
View File
@@ -0,0 +1,4 @@
// Request M*LIB to define functions
// This include both m-string functions and array_str templated functions
#define M_USE_EXTERN_DEF
#include "exm-header.h"
+14
View File
@@ -0,0 +1,14 @@
#include "exm-header.h"
int main(void)
{
array_str_t a;
array_str_init(a);
array_str_emplace_back(a, "Hello");
array_str_emplace_back(a, "World");
printf("a=");
array_str_out_str(stdout, a);
printf("\n");
array_str_clear(a);
return 0;
}
+19
View File
@@ -0,0 +1,19 @@
#ifndef MY_HEADER
#define MY_HEADER
// Request M*LIB to not always inline functions
#define M_USE_EXTERN_FINE_GRAINED 1
#include "m-string.h"
#include "m-array.h"
// The following functions will not be inlined:
#undef M_USE_EXTERN_FINE_SELECT
#ifdef EXN_LIB
#define M_USE_EXTERN_FINE_SELECT 3
#else
#define M_USE_EXTERN_FINE_SELECT 2
#endif
ARRAY_DEF(array_str, string_t)
#endif
+4
View File
@@ -0,0 +1,4 @@
// Request M*LIB to define functions for templated array functions.
#define EXN_LIB 3
#include "exn-header.h"
+19
View File
@@ -0,0 +1,19 @@
#include "exn-header.h"
int main(void)
{
string_t s;
string_init_set_str(s, "a=");
string_fputs(stdout, s);
string_clear(s);
array_str_t a;
array_str_init(a);
array_str_emplace_back(a, "Hello");
array_str_emplace_back(a, "World");
//printf("a=");
array_str_out_str(stdout, a);
printf("\n");
array_str_clear(a);
//main2();
return 0;
}