view test/strinit.c @ 874:3454953b3df0

fix inline strinit not yet worked.
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 01 Apr 2014 23:25:05 +0900
parents c55337499f96
children 528595192871
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 {
   long a;
   long b;
   long c;
   long d;
    struct hoge {
	long k;
	long j;
    } m;
   long e;
} temp1 = {
//   101,
//   102,
//   103,
//   104,
//   105,
   .e = 5,
   .a = 3
};

struct temp temp3 = {
   .c = (long)&b,
   .d = -10,
   .a = (long)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("#0131:%x %x\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("#0149:%x %x\n",fl.oif,fl.uli_u.ports.dport);
        printf("#0150:%x %x\n",fl.iif,fl.nl_u.ip4_u.saddr);
}

INLINE static 
void ip_route_connect1(/* struct rtable **rp, */ u32 dst,
                                   u32 src, u32 tos, int oif, u8 protocol,
                                   u16 sport, u16 dport /*, struct sock *sk */)
{
        struct flowi fl, *flp; 
      fl = (struct flowi){ .oif = oif,
                            .iif = 55,
                            .nl_u = { .ip4_u = { .daddr = dst,
                                                 .saddr = 66,
                                                 .tos = tos } },
                            .proto = protocol,
                            .uli_u = { .ports =
                                       { .sport = sport,
                                         .dport = dport } } };
       flp = &fl;

        printf("#0170:%x %x\n",flp->oif,flp->uli_u.ports.dport);
        printf("#0171:%x %x\n",flp->iif,flp->nl_u.ip4_u.saddr);
}

INLINE void
linux_kernel()
{
    int i=1,j=2;
    printf("#0178:%d %d\n",i,j);
    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);
    ip_route_connect1(1,2,3,4,5,6,7);
}

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("#0201:st1.ch   = %c\n",st1.ch);
  printf("#0202:st1.s1.a = %d\n",st1.s1.a);
  printf("#0203:st1.s1.b = %d\n",st1.s1.b);
  printf("#0204:st1.s1.c = %c\n",st1.s1.c);
  printf("#0205:st1.i    = %d\n",st1.i);
  printf("#0206:st1.j    = %d\n\n",st1.j);

  printf("#0208:st2.a = %d\n",st2.a);
  printf("#0209:st2.b = %d\n",st2.b);
  printf("#0210:st2.c = %c\n",st2.c);
  
  return;

}



struct arg { int hage, fuga; int aho; };

INLINE void f(struct arg h) {
    printf("#0221:%d %d %d\n",h.hage,h.fuga,h.aho);
}

INLINE int main8() {
     f((struct arg){.fuga = 3,.aho=5});
     printf("#0226:%d\n",((struct arg){.aho=120, .hage=55}).aho); return 0;
}

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 = (long)&b,
    };
    struct temp temp12 = {
       .m = (struct hoge){1,3},
       .c = (long)&temp4,
    };
    int c[3] = {1,2,3};

    printf("#0251:1: %ld\n",temp1.a);
    printf("#0252:1: %ld\n",temp1.e);
    printf("#0253:1: %ld\n",temp1.b);
    printf("#0254:2: %ld\n",temp2.c);
    printf("#0255:2: %ld\n",temp2.e);
    printf("#0256:2: %ld\n",temp2.b);
    printf("#0257:2: %d\n",(void*)temp3.c==b);
    printf("#0258:2: %d\n",temp3.c==(long)b);
    printf("#0259:2: %d\n",temp3.a==(long)&b);
    printf("#0260:2: %ld\n",temp4.m.j);
    printf("#0261:2: %ld\n",temp5.m.j);
    printf("#0262:2: %ld\n",temp11.m.j);
    printf("#0263:2: %ld\n",temp12.m.k);
    printf("#0264:2: %ld\n",temp12.m.j);
    printf("#0265:2: %d\n",temp11.c==(long)&b);
    printf("#0266:2: %ld\n",temp8.e);
    printf("#0267:2: %ld\n",temp6.e);
    main7();
    main8();
    linux_kernel();
    int i=1,j=2;
    printf("#0272:%d %d\n",i,j);

    printf("#0274:b %d %d %d\n",b[0],b[1],b[2]);
    printf("#0275:c %d %d %d\n",c[0],c[1],c[2]);

    struct test t = {1,2,3};
    printf("#0278:t %d %d %d\n",t.a,t.b,t.c);

    struct test3 {
	int a,b,c;
    } *p, q, d = {
	1,2,3,
    };
    printf("#0285:d %d %d %d\n",d.a,d.b,d.c);
    p = & (struct test3) {1,2,3};
    printf("#0287:p %d %d %d\n",p->a,p->b,p->c);
    q =  (struct test3) {1,2,3};
    printf("#0289:q %d %d %d\n",q.a,q.b,q.c);

    struct test4 {
	struct test5 {
	    int a,b,c;
	} d; 
    } u = { .d = {1,2,3} };
    struct test4 v = { .d = (struct test5){1,2,3} };
    
    printf("#0298:u %d %d %d\n",u.d.a,u.d.b,u.d.c);

    printf("#0300:v %d %d %d\n",v.d.a,v.d.b,v.d.c);


    return 0;
}



// end