Skip to content

Instantly share code, notes, and snippets.

@iwadon
Created May 5, 2012 08:20
Show Gist options
  • Select an option

  • Save iwadon/2600879 to your computer and use it in GitHub Desktop.

Select an option

Save iwadon/2600879 to your computer and use it in GitHub Desktop.
CC = gcc
CC32 = gcc -m32
CC64 = gcc -m64
CFLAGS = -Wall -Wextra -g
CPPFLAGS =
LDFLAGS =
LIBS =
RM = rm -f
TARGETS = sizeof sizeof32 sizeof64
all: $(TARGETS)
clean:
$(RM) $(TARGETS)
sizeof: sizeof.c
$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ sizeof.c
sizeof32: sizeof.c
$(CC32) $(CFLAGS) $(CPPFLAGS) -o $@ sizeof.c
sizeof64: sizeof.c
$(CC64) $(CFLAGS) $(CPPFLAGS) -o $@ sizeof.c
#include <inttypes.h>
#include <limits.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
(void)argc;
(void)argv;
#ifdef __LP64__
#ifndef PRIuSIZE
printf("PRIuSIZE not defined\n");
#define PRIuSIZE "lu"
#endif
printf("__LP64__ defined\n");
#else
#ifndef PRIuSIZE
printf("PRIuSIZE not defined\n");
#if defined(__APPLE__)
#define PRIuSIZE "lu"
#else
#define PRIuSIZE "u"
#endif
#endif
printf("__LP64__ not defined\n");
#endif
#define PRINTF_SIZEOF(type) printf("sizeof (" #type ") = %" PRIuSIZE "\n", sizeof (type))
PRINTF_SIZEOF(int);
PRINTF_SIZEOF(long);
PRINTF_SIZEOF(int *);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment