Created
April 22, 2024 04:22
-
-
Save adammw/22fbc0c16e40cfd1241a874e3914a89d to your computer and use it in GitHub Desktop.
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
#ifdef __APPLE__ | |
#include <machine/endian.h> | |
#include <libkern/OSByteOrder.h> | |
#define le32toh(x) OSSwapLittleToHostInt32(x) | |
#else | |
#include <endian.h> | |
#endif | |
#include "main.h" | |
inline int32_t decode_int32(int32_t source) { | |
return le32toh(source); | |
} | |
int sample_func() { | |
int ret = decode_int32(0xff00); | |
return ret; | |
} |
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
package main | |
// #cgo CFLAGS: -I${SRCDIR}/ | |
// #include "main.h" | |
// #include <stdint.h> | |
import "C" | |
import "fmt" | |
func main() { | |
res := C.sample_func() | |
fmt.Printf("result=%d\n", res) | |
} |
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
#ifndef MAIN_H | |
#define MAIN_H | |
int sample_func(); | |
#endif // MAIN_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment