1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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,287
    Likes Received:
    364
    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