Re: DMCP_SDK Hello World
Posted: Sat Jun 16, 2018 7:42 pm
Some of those could be fixed, but avoiding the typeof keyword (a GCC extension) would make the dmcp/lft_ifc.h header file a lot uglier than it is already.Vitasam wrote: ↑Thu Jun 14, 2018 10:56 pmBut what is a policy of DM42 SDK - are we C99 compliant?
With following options:Code: Select all
CFLAGS += -std=c99 CFLAGS += -pedantic-errors
Code: Select all
DMCP_SDK$ make arm-none-eabi-gcc -c -mthumb -march=armv7e-m -mfloat-abi=hard -mfpu=fpv4-sp-d16 -D__weak="__attribute__((weak))" -D__packed="__attribute__((__packed__))" -Idmcp -Isrc -Wall -fdata-sections -ffunction-sections -Wno-misleading-indentation -std=c99 -pedantic-errors -O2 -g -MD -MP -MF .dep/pgm_syscalls.o.d -Wa,-a,-ad,-alms=build/pgm_syscalls.lst dmcp/sys/pgm_syscalls.c -o build/pgm_syscalls.o In file included from dmcp/sys/pgm_syscalls.c:44:0: dmcp/dmcp.h:474:14: error: redefinition of typedef 'void_fn_t' [-Wpedantic] typedef void void_fn_t(); ^ dmcp/dmcp.h:285:14: note: previous declaration of 'void_fn_t' was here typedef void void_fn_t(); ^ dmcp/sys/pgm_syscalls.c:54:2: error: ISO C forbids conversion of function pointer to object pointer type [-Wpedantic] (void*)Program_Entry, // void * pgm_entry; ^ dmcp/sys/pgm_syscalls.c: In function 'free': dmcp/sys/pgm_syscalls.c:113:2: error: implicit declaration of function 'typeof' [-Wimplicit-function-declaration] __sysfn_free(ptr); ^ In file included from dmcp/dmcp.h:841:0, from dmcp/sys/pgm_syscalls.c:44: dmcp/lft_ifc.h:38:38: error: expected expression before ')' token #define __sysfn_free (*(typeof(free)*)(LIBRARY_FN_BASE+4)) ^ dmcp/sys/pgm_syscalls.c:113:2: note: in expansion of macro '__sysfn_free' __sysfn_free(ptr); ^ dmcp/sys/pgm_syscalls.c: In function 'malloc': dmcp/lft_ifc.h:37:42: error: expected expression before ')' token #define __sysfn_malloc (*(typeof(malloc)*)(LIBRARY_FN_BASE+0)) ^ dmcp/sys/pgm_syscalls.c:118:9: note: in expansion of macro '__sysfn_malloc' return __sysfn_malloc(size); ^ dmcp/sys/pgm_syscalls.c: In function 'calloc': dmcp/lft_ifc.h:39:42: error: expected expression before ')' token #define __sysfn_calloc (*(typeof(calloc)*)(LIBRARY_FN_BASE+8)) ^ dmcp/sys/pgm_syscalls.c:123:9: note: in expansion of macro '__sysfn_calloc' return __sysfn_calloc(count, nbytes); ^ dmcp/sys/pgm_syscalls.c: In function 'realloc': dmcp/lft_ifc.h:40:44: error: expected expression before ')' token #define __sysfn_realloc (*(typeof(realloc)*)(LIBRARY_FN_BASE+12)) ^ dmcp/sys/pgm_syscalls.c:127:9: note: in expansion of macro '__sysfn_realloc' return __sysfn_realloc(ptr, size); ^ dmcp/sys/pgm_syscalls.c: In function 'post_main': dmcp/lft_ifc.h:105:52: error: expected expression before ')' token #define set_reset_magic (*(typeof(set_reset_magic)*)(LIBRARY_FN_BASE+272)) ^ dmcp/sys/pgm_syscalls.c:151:2: note: in expansion of macro 'set_reset_magic' set_reset_magic(RUN_DMCP_MAGIC); ^ dmcp/lft_ifc.h:173:40: error: expected expression before ')' token #define sys_reset (*(typeof(sys_reset)*)(LIBRARY_FN_BASE+544)) ^ dmcp/sys/pgm_syscalls.c:152:2: note: in expansion of macro 'sys_reset' sys_reset(); ^ /usr/include/newlib/stdlib.h: In function 'malloc': dmcp/sys/pgm_syscalls.c:119:1: warning: control reaches end of non-void function [-Wreturn-type] } ^ /usr/include/newlib/stdlib.h: In function 'calloc': dmcp/sys/pgm_syscalls.c:124:1: warning: control reaches end of non-void function [-Wreturn-type] } ^ /usr/include/newlib/stdlib.h: In function 'realloc': dmcp/sys/pgm_syscalls.c:128:1: warning: control reaches end of non-void function [-Wreturn-type] } ^ dmcp/sys/pgm_syscalls.c: At top level: cc1: warning: unrecognized command line option "-Wno-misleading-indentation" Makefile:132: recipe for target 'build/pgm_syscalls.o' failed make: *** [build/pgm_syscalls.o] Error 1
Also, the C++ sources make use of variable length arrays (VLAs) which are not standard C++, so that would have to be worked around somehow. Not sure it's worth it.
However, using -pedantic is useful for spotting some places that could easily be made more standard.
Setting CFLAGS += -std=c99 in the Makefile currently makes that end up in CXXFLAGS too, so it would need a bit of Makefile hacking to separate the "C only" flags from the "C and C++" flags.