• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
  • 請教sizeof()里面的值?

    發表于:2007-05-25來源:作者:點擊數: 標簽:structSizeof請教面的Example
    example:struct in_addr in_valchar addrptr[BUFSIZE];mmcpy(addrptr,in_val,sizefo(struct in_addr));connect(sockfd,(socket (const sturct sockaddr *)serv,sizeof(serv)); mmcpy(addrptr,in_val,sizefo(struct in_addr)); 這個sizeof(你打反了)是復制
    example:
    struct in_addr   in_val
    char            addrptr[BUFSIZE];
    mmcpy(addrptr,&in_val,sizefo(struct in_addr));
    
    
    
    connect(sockfd,(socket (const sturct sockaddr *)&serv,sizeof(serv));

    mmcpy(addrptr,&in_val,sizefo(struct in_addr));
    這個sizeof(你打反了)是復制過程,長度是struct in_addre長度
    connect(sockfd,(socket (const sturct sockaddr *)&serv,sizeof(serv));
    這個sizeof是serv這個里面結構的長度,因為實際中很可能某些結構中有空的項
    比如gethostname(好象是這個函數得到主機的dns信息,忘記了……)
    它里面的結構中允許主機的ip和主機名是多項的,但是如果不滿的話就是空,那么長度可能比原來的小
    所以是用sizeof 實際結構長度
    我理解是醬紫的
    devel :
    謝謝??!我懂了。。用數據類型和用該數據類型的變量的結果一樣。
    以下的程序是打印出你的系統的數據類型占用的內存空間。
    struct A {
    int a;
    };

    int
    main(void)
    {
        printf("int                %d\n",sizeof(int));
        printf("int *              %d\n",sizeof(int *));
        printf("unsigned           %d\n",sizeof(unsigned));
        printf("unsigned int *      %d\n",sizeof(unsigned int *));

        printf("long               %d\n",sizeof(long));
        printf("long *             %d\n",sizeof(long *));
        printf("unsigned long       %d\n",sizeof(unsigned long));
        printf("unsigned long *     %d\n",sizeof(unsigned long *));

        printf("char               %d\n",sizeof(char));
        printf("char *             %d\n",sizeof(char *));
        printf("unsigned char       %d\n",sizeof(unsigned char));
        printf("unsigned char *     %d\n",sizeof(unsigned char *));
        
        printf("struct A            %d\n",sizeof(struct A));
        printf("struct A *          %d\n",sizeof(struct A *));
        return(0);
    }

    原文轉自:http://www.kjueaiud.com

    評論列表(網友評論僅供網友表達個人看法,并不表明本站同意其觀點或證實其描述)
    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>