Created
May 14, 2013 07:00
-
-
Save xxuejie/5574172 to your computer and use it in GitHub Desktop.
va_arg bug
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
$ clang vatest.c | |
$ ./a.out | |
Type is 0 | |
Value is 5 | |
Type is 1 | |
Value is 12 | |
Type is 2 | |
Value is 19 | |
Type is 3 | |
Value is 26 | |
Type is 4 | |
Value is 33 |
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
$ emcc vatest.c | |
clang: warning: argument unused during compilation: '-nostdinc++' | |
vatest.c:25:17: error: cannot compile this aggregate va_arg expression yet | |
print_value(va_arg(ap, mrb_value)); | |
^~~~~~~~~~~~~~~~~~~~~ | |
/Users/rafael/develop/webruby/modules/emscripten/system/include/libc/stdarg.h:35:29: note: expanded from macro 'va_arg' | |
#define va_arg(ap, type) __builtin_va_arg(ap, type) | |
^~~~~~~~~~~~~~~~~~~~~~~~~~ | |
1 error generated. | |
ERROR emcc: compiler frontend failed to generate LLVM bitcode, halting |
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 mrb_value { | |
union { | |
float f; | |
void *p; | |
int i; | |
short sym; | |
} value; | |
unsigned tt; | |
} mrb_value; | |
void print_value(mrb_value val) | |
{ | |
printf("Type is %d\n", val.tt); | |
printf("Value is %d\n", val.value.i); | |
} | |
void print_list(int n, va_list ap) | |
{ | |
int i; | |
for (i = 0; i < n; i++) { | |
print_value(va_arg(ap, mrb_value)); | |
} | |
} | |
void print_variable_length(int n, ...) | |
{ | |
va_list ap; | |
va_start(ap, n); | |
print_list(n, ap); | |
va_end(ap); | |
} | |
int main () | |
{ | |
mrb_value values[5]; | |
int i; | |
for (i = 0; i < 5; i++) { | |
values[i].tt = i; | |
values[i].value.i = i * 7 + 5; | |
} | |
print_variable_length(5, values[0], values[1], values[2], values[3], values[4]); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment