Skip to content

Instantly share code, notes, and snippets.

@ryochack
ryochack / extern_sizecheck.c
Created May 20, 2014 18:06
externの配列定義を使ったビルド時の配列サイズチェック方法 (MINIX3より)
#define RESOURCE_NUM (8)
#define ARRAY_NUM (8)
struct resource {
int id;
unsigned int addr;
int len;
};
struct resource rscs[] = {
@ryochack
ryochack / resource.inc
Created May 20, 2014 15:43
#includeを使ってビルド時にenumのインデックスと配列データの整合性を確保する方法
/* resource_id, addr, len */
RESOURCE( E_RSC01, 0x10, 4 ),
RESOURCE( E_RSC02, 0x14, 2 ),
RESOURCE( E_RSC03, 0x16, 2 ),
RESOURCE( E_RSC04, 0x18, 4 ),
RESOURCE( E_RSC05, 0x20, 1 ),
RESOURCE( E_RSC06, 0x21, 1 ),
RESOURCE( E_RSC07, 0x22, 2 ),
RESOURCE( E_RSC08, 0x24, 4 ),
@ryochack
ryochack / 20140316-205912.go
Created March 16, 2014 13:28
golang reflection: interface of array
package main
import (
"fmt"
"reflect"
)
func dump_interface_array(args interface{}) {
val := reflect.ValueOf(args)
fmt.Println(val.Kind())
package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
const (
package main
import (
"fmt"
"os"
"bufio"
"strconv"
)
const (
// process communication using message queue
// ack version
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// process communication using message queue
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MSGLEN (16)
package main
import (
"fmt"
"sync"
)
var wg sync.WaitGroup
func f(msg string, n int) chan string {
package main
import (
"fmt"
"sync"
)
func f(msg string, n int) chan string {
ch := make(chan string)
go func() {
package main
import (
"fmt"
)
func f(msg string, n int) (chan string, chan bool) {
ch := make(chan string)
done := make(chan bool)
go func() {