Skip to content

Instantly share code, notes, and snippets.

@kylelemons
Created July 3, 2012 17:21
Show Gist options
  • Save kylelemons/3041155 to your computer and use it in GitHub Desktop.
Save kylelemons/3041155 to your computer and use it in GitHub Desktop.
I don't recommend it, but you can preprocess Go code.
/*
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