Bit Field Problem

Discussion in 'C' started by shyam_oec, Jun 14, 2008.

  1. shyam_oec

    shyam_oec New Member

    Joined:
    Nov 26, 2007
    Messages:
    89
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    Software Developer, .NET Framework
    Location:
    Jamshedpur
    Consider the declaration:



    main()
    {
    struct num
    {
    a:1;
    };

    struct num A;
    A.a=0;
    printf("%d",A.a);
    }



    It gave output 0,that's fine.

    Now consider the declaration :

    main()
    {

    a:1;
    a=0;
    printf("%d",a);
    }


    It gave error that code a:1 has no effect and that a is undefined.

    with reference to the above i am Bit Confused about structure!!!That what structure has done in the first code,and why error in the absence of structure occured???
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    I think the error should occur for first one as well but a:1 cannot be a variable declaration or at least I don't know if such things can be defined.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice