Created
July 3, 2012 17:21
-
-
Save kylelemons/3041155 to your computer and use it in GitHub Desktop.
I don't recommend it, but you can preprocess Go code.
This file contains hidden or 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
/* | |
You can preprocess this using the following: | |
gcc -E -x c -P -C main.go | |
*/ | |
/* abs.h */ | |
#define ABS(N, T) func Abs##N(v T) T { \ | |
; if v < 0 { \ | |
; return -v \ | |
; } \ | |
; return v \ | |
} | |
/* main.go */ | |
package main | |
import ( | |
"fmt" | |
) | |
#include "abs.h" | |
ABS(Int, int) | |
ABS(Float, float) | |
func main() { | |
fmt.Println(AbsInt(-42), AbsFloat(-3.1415)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment