Skip to content
This repository was archived by the owner on Jan 8, 2025. It is now read-only.

Commit

Permalink
[stdlib] add countof()
Browse files Browse the repository at this point in the history
  • Loading branch information
travisg authored and Ajay Dudani committed Jul 28, 2011
1 parent b29c3ba commit 84aa16c
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions include/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@
#define __WEAK __attribute__((weak))
#define __GNU_INLINE __attribute__((gnu_inline))
#define __GET_CALLER(x) __builtin_return_address(0)
#define __GET_FRAME(x) __builtin_frame_address(0)

#define INCBIN(symname, sizename, filename, section) \
__asm__ (".section " section "; .align 4; .globl "#symname); \
__asm__ (""#symname ":\n.incbin \"" filename "\""); \
__asm__ (".section " section "; .align 1;"); \
__asm__ (""#symname "_end:"); \
__asm__ (".section " section "; .align 4; .globl "#sizename); \
__asm__ (""#sizename ": .long "#symname "_end - "#symname " - 1"); \
extern unsigned char symname[]; \
extern unsigned int sizename

#define INCFILE(symname, sizename, filename) INCBIN(symname, sizename, filename, ".rodata")

/* look for gcc 3.0 and above */
#if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 0)
Expand Down Expand Up @@ -106,4 +119,7 @@

#endif

/* TODO: add type check */
#define countof(a) (sizeof(a) / sizeof((a)[0]))

#endif

0 comments on commit 84aa16c

Please sign in to comment.