Mercurial > hg > CbC > old > device
view test/strinit.c @ 666:7c42cf329666
*** empty log message ***
author | kono |
---|---|
date | Mon, 30 Apr 2007 02:19:48 +0900 |
parents | 8320ae3ac186 |
children | 639db8597a58 |
line wrap: on
line source
#include <stdio.h> #ifndef INLINE #define INLINE #endif INLINE void main7(); INLINE int main8(); int b[3] = {1,2,3}; struct temp { int a; int b; int c; int d; struct hoge { int k; int j; } m; int e; } temp1 = { // 101, // 102, // 103, // 104, // 105, .e = 5, .a = 3 }; struct temp temp3 = { .c = (int)&b, .d = -10, .a = (int)b }; struct temp temp4 = { 1,2,3,4,5,6,7}; struct temp temp7 = { 1,2,3,4,{5,6},7}; #if 0 struct temp temp10 = { .m = (struct hoge){}, // not allowed in global .c = (int)&b, }; #endif INLINE void linux_kernel(); struct test{ int a,b,c; } huga = { 0,0,0, }; typedef unsigned int __u32; typedef unsigned short __u16; typedef unsigned char __u8; typedef unsigned int u32; typedef unsigned short u16; typedef unsigned char u8; struct in6_addr { char hoge[128]; }; struct flowi { int oif; int iif; union { struct { __u32 daddr; __u32 saddr; __u32 fwmark; __u8 tos; __u8 scope; } ip4_u; struct { struct in6_addr daddr; struct in6_addr saddr; __u32 flowlabel; } ip6_u; struct { __u16 daddr; __u16 saddr; __u32 fwmark; __u8 scope; } dn_u; } nl_u; __u8 proto; __u8 flags; union { struct { __u16 sport; __u16 dport; } ports; struct { __u8 type; __u8 code__; } icmpt; struct { __u16 sport; __u16 dport; __u8 objnum; __u8 objnamel; __u8 objname[16]; } dnports; __u32 spi; } uli_u; } __attribute__((__aligned__(32/8))); INLINE static __inline__ __attribute__((always_inline)) __attribute__((always_inline)) void ip_route_connect(/* struct rtable **rp, */ u32 dst, u32 src, u32 tos, int oif, u8 protocol, u16 sport, u16 dport /*, struct sock *sk */) { struct flowi fl = { .oif = oif, .nl_u = { .ip4_u = { .daddr = dst, .saddr = src, .tos = tos } }, .proto = protocol, .uli_u = { .ports = { .sport = sport, .dport = dport } } }; printf("#0166:%d %d\n",fl.oif,fl.uli_u.ports.dport); } INLINE static void ip_route_connect0(/* struct rtable **rp, */ u32 dst, u32 src, u32 tos, int oif, u8 protocol, u16 sport, u16 dport /*, struct sock *sk */) { struct flowi fl = { .oif = oif, .iif = 55, .nl_u = { .ip4_u = { .daddr = dst, .saddr = 66, .tos = tos } }, .proto = protocol, .uli_u = { .ports = { .sport = sport, .dport = dport } } }; printf("#0184:%d %d\n",fl.oif,fl.uli_u.ports.dport); printf("#0185:%d %d\n",fl.iif,fl.nl_u.ip4_u.saddr); } INLINE void linux_kernel() { ip_route_connect0(1,2,3,4,5,6,7); ip_route_connect(1,2,3,4,5,6,7); ip_route_connect(11,12,13,14,15,16,17); } struct st_child { int a,b; char c; }; struct st_parent{ char ch; struct st_child s1; int i,j; }; INLINE void main7() { struct st_parent st1 = {'A',{1,2,'E'},5,6}; struct st_child st2 = {10,11,'F'}; printf("st1.ch = %c\n",st1.ch); printf("st1.s1.a = %d\n",st1.s1.a); printf("st1.s1.b = %d\n",st1.s1.b); printf("st1.s1.c = %c\n",st1.s1.c); printf("st1.i = %d\n",st1.i); printf("st1.j = %d\n\n",st1.j); printf("st2.a = %d\n",st2.a); printf("st2.b = %d\n",st2.b); printf("st2.c = %c\n",st2.c); return; } struct arg { int hage, fuga; int aho; }; INLINE void f(struct arg h) { printf("%d %d %d\n",h.hage,h.fuga,h.aho); } INLINE int main8() { f((struct arg){.fuga = 3,.aho=5}); printf("%d\n",((struct arg){.aho=120, .hage=55}).aho); } int main() { struct temp temp2 = { .c = 5, .e=99 }; #ifdef WRONG struct temp temp5 = { 1,2,3,4,5,6,7,8}; struct temp temp6 = { 1,2,3,4,5,6}; #else struct temp temp5 = { 1,2,3,4,5,6,7}; struct temp temp6 = { 1,2,3,4,5,6,7}; struct temp temp8 = { 1,2,3,4,{5,6},7}; #endif struct temp temp11 = { .m = (struct hoge){}, .c = (int)&b, }; struct temp temp12 = { .m = (struct hoge){1,3}, .c = (int)&temp4, }; printf("#0070:1: %d\n",temp1.a); printf("#0071:1: %d\n",temp1.e); printf("#0072:1: %d\n",temp1.b); printf("#0073:2: %d\n",temp2.c); printf("#0074:2: %d\n",temp2.e); printf("#0075:2: %d\n",temp2.b); printf("#0076:2: %d\n",(void*)temp3.c==b); printf("#0077:2: %d\n",temp3.c==(int)b); printf("#0078:2: %d\n",temp3.a==(int)&b); printf("#0079:2: %d\n",temp4.m.j); printf("#0080:2: %d\n",temp5.m.j); printf("#0081:2: %d\n",temp11.m.j); printf("#0082:2: %d\n",temp12.m.k); printf("#0083:2: %d\n",temp12.m.j); printf("#0084:2: %d\n",temp11.c==(int)&b); printf("#0085:2: %d\n",temp8.e); printf("#0086:2: %d\n",temp6.e); main7(); main8(); linux_kernel(); return 0; } // end