Created
November 13, 2012 01:58
va_arg bug of emscripten
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdarg.h> | |
typedef struct type_a { | |
union { | |
double f; | |
void *p; | |
int i; | |
short sym; | |
} value; | |
} type_a; | |
enum mrb_vtype { | |
MRB_TT_FALSE = 0, /* 0 */ | |
MRB_TT_CLASS = 9 /* 9 */ | |
}; | |
typedef struct type_b { | |
enum mrb_vtype tt:8; | |
} type_b; | |
void print_type_a(int argc, ...); | |
void print_type_b(int argc, ...); | |
int main(int argc, char *argv[]) | |
{ | |
type_a a; | |
type_b b; | |
a.value.p = (void*) 0x12345678; | |
b.tt = MRB_TT_CLASS; | |
printf("The original address of a is: %p\n", a.value.p); | |
printf("The original type of b is: %d\n", b.tt); | |
print_type_a(1, a); | |
print_type_b(1, b); | |
return 0; | |
} | |
void print_type_a(int argc, ...) { | |
va_list ap; | |
type_a a; | |
va_start(ap, argc); | |
a = va_arg(ap, type_a); | |
va_end(ap); | |
printf("The current address of a is: %p\n", a.value.p); | |
} | |
void print_type_b(int argc, ...) { | |
va_list ap; | |
type_b b; | |
va_start(ap, argc); | |
b = va_arg(ap, type_b); | |
va_end(ap); | |
printf("The current type of b is: %d\n", b.tt); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment