Skip to content

Instantly share code, notes, and snippets.

@rmcgibbo
Created November 13, 2012 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rmcgibbo/4065801 to your computer and use it in GitHub Desktop.
Save rmcgibbo/4065801 to your computer and use it in GitHub Desktop.
What is going on!!!!
#include <stdio.h>
#ifdef HEADER
#include "lib.h"
#endif
int main(int argc, char* argv[]) {
float a = 5.0;
int b = 10;
double c = 2.0;
printf("in main, float a = %f\n", a);
printf("in main, int b = %d\n", b);
printf("in main, double c = %f\n", c);
printf("Calling functions...\n");
g_float(a);
g_int(b);
g_double(c);
return 1;
}
#include <stdio.h>
#include "lib.h"
void g_float(float a) {
printf("In g_float, you passed a = %f\n", a);
}
void g_int(int b) {
printf("In g_int, you passed b = %d\n", b);
}
void g_double(double c) {
printf("In g_double, you passed c = %f\n", c);
}
#ifndef LIB_H
#define LIB_H
void g_float(float a);
void g_int(int b);
void g_double(double c);
#endif
all:
gcc -DHEADER client.c lib.c -o withheader
gcc client.c lib.c -o withoutheader
rmcgibbo@Roberts-MacBook-Pro-2 ~/local/mdtraj/ctest
$ gcc --v
Using built-in specs.
Target: i686-apple-darwin11
Configured with: /private/var/tmp/llvmgcc42/llvmgcc42-2335.15~25/src/configure --disable-checking --enable-werror --prefix=/Developer/usr/llvm-gcc-4.2 --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-prefix=llvm- --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin11 --enable-llvm=/private/var/tmp/llvmgcc42/llvmgcc42-2335.15~25/dst-llvmCore/Developer/usr/local --program-prefix=i686-apple-darwin11- --host=x86_64-apple-darwin11 --target=i686-apple-darwin11 --with-gxx-include-dir=/usr/include/c++/4.2.1
Thread model: posix
gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)
rmcgibbo@Roberts-MacBook-Pro-2 ~/local/mdtraj/ctest
$ make
gcc -DHEADER client.c lib.c -o withheader
gcc client.c lib.c -o withoutheader
rmcgibbo@Roberts-MacBook-Pro-2 ~/local/mdtraj/ctest
$ ./withheader
in main, float a = 5.000000
in main, int b = 10
in main, double c = 2.000000
Calling functions...
In g_float, you passed a = 5.000000
In g_int, you passed b = 10
In g_double, you passed c = 2.000000
rmcgibbo@Roberts-MacBook-Pro-2 ~/local/mdtraj/ctest
$ ./withoutheader
in main, float a = 5.000000
in main, int b = 10
in main, double c = 2.000000
Calling functions...
In g_float, you passed a = 0.000000
In g_int, you passed b = 10
In g_double, you passed c = 2.000000
@rmcgibbo
Copy link
Author

Take a look at line 20 vs line 30 in the stdout file.

WHAT IS HAPPENING?

@rmcgibbo
Copy link
Author

it's not really that crazy, but it's still annoying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment