compilation error in structure

Discussion in 'C Programming' started by Puneet, Aug 22, 2003.

  1. Puneet

    Puneet Guest

    hi,

    i wrote this structre. after first compilation i am getting "C uses
    undefined struct pcap". what it is so.

    struct pcap_hdr {
    _int16 version_major; /* major version number */
    _int16 version_minor; /* minor version number */
    _int32 thiszone; /* GMT to local correction */
    _int32 sigfigs; /* accuracy of timestamps */
    _int32 snaplen; /* max length in octets */
    _int32 network; /* data link type */
    }pcap;

    main(){

    int bytes_read;
    int magic;
    struct pcap C;
    --
    --
    --
    }
     
    Puneet, Aug 22, 2003
    #1
    1. Advertising

  2. [FAQ] Re: compilation error in structure

    On Fri, 22 Aug 2003, Puneet wrote:
    >
    > i wrote this structre. after first compilation i am getting "C uses
    > undefined struct pcap". what it is so.
    >
    > struct pcap_hdr {

    ^^^^^^^^
    > _int16 version_major; /* major version number */
    > _int16 version_minor; /* minor version number */
    > _int32 thiszone; /* GMT to local correction */
    > _int32 sigfigs; /* accuracy of timestamps */
    > _int32 snaplen; /* max length in octets */
    > _int32 network; /* data link type */
    > }pcap;
    >
    > main(){
    >
    > int bytes_read;
    > int magic;
    > struct pcap C;

    ^^^^

    http://www.google.com/search?q=c faq&btnI=Im Feeling Lucky

    -Arthur
     
    Arthur J. O'Dwyer, Aug 22, 2003
    #2
    1. Advertising

  3. Puneet

    Mike Wahler Guest

    Puneet <> wrote in message
    news:...
    > hi,
    >
    > i wrote this structre. after first compilation i am getting "C uses
    > undefined struct pcap". what it is so.
    >
    > struct pcap_hdr


    > _int16 version_major; /* major version number */
    > _int16 version_minor; /* minor version number */
    > _int32 thiszone; /* GMT to local correction */
    > _int32 sigfigs; /* accuracy of timestamps */
    > _int32 snaplen; /* max length in octets */
    > _int32 network; /* data link type */
    > }pcap;
    >
    >

    n(){
    >
    > int bytes_read;
    > int magic;
    > struct pcap C;


    struct pcap_hdr C;

    What you intend to do with the above type 'struct pcap_hdr'
    object, named 'pcap' I don't know. :)

    Did you perhaps mean to write a typedef?

    -Mike
     
    Mike Wahler, Aug 22, 2003
    #3
  4. Puneet wrote:

    > hi,
    >
    > i wrote this structre. after first compilation i am getting "C uses
    > undefined struct pcap". what it is so.
    >
    > struct pcap_hdr {
    > _int16 version_major; /* major version number */
    > _int16 version_minor; /* minor version number */
    > _int32 thiszone; /* GMT to local correction */
    > _int32 sigfigs; /* accuracy of timestamps */
    > _int32 snaplen; /* max length in octets */
    > _int32 network; /* data link type */
    > }pcap;



    Of course you know already that all those _int16 and _int32 types are
    non-portable, non-standard, and off topic here. Leaving that aside, you
    have here defined a type 'struct pcap_hdr' and an object of that type
    'pcap'. If you mean pcap to be a type, you need to precede 'struct
    pcap_hdr' with 'typedef', in which case the tag 'pcap-hdr' is superfluous.


    >
    > main(){


    This should, of course, be 'int main(void)'. main returns an int, and you
    should say so. In C99 the implicit int of your form is disallowed, and
    it's bad practice anyway.

    >
    > int bytes_read;
    > int magic;
    > struct pcap C;


    There is no type 'struct pcap'. This should be 'struct pcap-hdr C;' or, if
    you use typedef as I suggested above, just 'pcap C;'.



    --
    Martin Ambuhl
     
    Martin Ambuhl, Aug 22, 2003
    #4
  5. Puneet

    Eric Sosman Guest

    Puneet wrote:
    >
    > hi,
    >
    > i wrote this structre. after first compilation i am getting "C uses
    > undefined struct pcap". what it is so.
    >
    > struct pcap_hdr {


    "I am defining a new struct type called `struct pcap_hdr',
    containing the elements listed below."

    > _int16 version_major; /* major version number */
    > _int16 version_minor; /* minor version number */
    > _int32 thiszone; /* GMT to local correction */
    > _int32 sigfigs; /* accuracy of timestamps */
    > _int32 snaplen; /* max length in octets */
    > _int32 network; /* data link type */
    > }pcap;


    "I am defining a variable named `pcap', an instance of
    the `struct pcap_hdr' type."

    > main(){
    >
    > int bytes_read;
    > int magic;
    > struct pcap C;


    Compiler: "What is this `struct pcap' you're talking about?
    I know about a type named `struct pcap_hdr', and I know about
    a variable named `pcap', but I've never heard of `struct pcap'
    before. Pppphhhht!"

    --
     
    Eric Sosman, Aug 22, 2003
    #5
  6. Puneet

    Derk Gwen Guest

    (Puneet) wrote:
    # hi,
    #
    # i wrote this structre. after first compilation i am getting "C uses
    # undefined struct pcap". what it is so.
    #
    # struct pcap_hdr {
    # _int16 version_major; /* major version number */
    # _int16 version_minor; /* minor version number */
    # _int32 thiszone; /* GMT to local correction */
    # _int32 sigfigs; /* accuracy of timestamps */
    # _int32 snaplen; /* max length in octets */
    # _int32 network; /* data link type */
    # }pcap;
    #
    # main(){
    #
    # int bytes_read;
    # int magic;
    # struct pcap C;

    The struct tag is pcap_hdr, and would be used
    struct pcap_hdr C;
    "pcap" by itself is a global variable name.

    --
    Derk Gwen http://derkgwen.250free.com/html/index.html
    I hope it feels so good to be right. There's nothing more
    exhilirating pointing out the shortcomings of others, is there?
     
    Derk Gwen, Aug 23, 2003
    #6
  7. Puneet

    Derk Gwen Guest

    (Puneet) wrote:
    # hi,
    #
    # i wrote this structre. after first compilation i am getting "C uses
    # undefined struct pcap". what it is so.
    #
    # struct pcap_hdr {
    # _int16 version_major; /* major version number */
    # _int16 version_minor; /* minor version number */
    # _int32 thiszone; /* GMT to local correction */
    # _int32 sigfigs; /* accuracy of timestamps */
    # _int32 snaplen; /* max length in octets */
    # _int32 network; /* data link type */
    # }pcap;
    #
    # main(){
    #
    # int bytes_read;
    # int magic;
    # struct pcap C;

    The struct tag is pcap_hdr, and would be used
    struct pcap_hdr C;
    "pcap" by itself is a global variable name.

    --
    Derk Gwen http://derkgwen.250free.com/html/index.html
    I hope it feels so good to be right. There's nothing more
    exhilirating pointing out the shortcomings of others, is there?
     
    Derk Gwen, Aug 23, 2003
    #7
  8. Puneet

    Derk Gwen Guest

    (Puneet) wrote:
    # hi,
    #
    # i wrote this structre. after first compilation i am getting "C uses
    # undefined struct pcap". what it is so.
    #
    # struct pcap_hdr {
    # _int16 version_major; /* major version number */
    # _int16 version_minor; /* minor version number */
    # _int32 thiszone; /* GMT to local correction */
    # _int32 sigfigs; /* accuracy of timestamps */
    # _int32 snaplen; /* max length in octets */
    # _int32 network; /* data link type */
    # }pcap;
    #
    # main(){
    #
    # int bytes_read;
    # int magic;
    # struct pcap C;

    The struct tag is pcap_hdr, and would be used
    struct pcap_hdr C;
    "pcap" by itself is a global variable name.

    --
    Derk Gwen http://derkgwen.250free.com/html/index.html
    I hope it feels so good to be right. There's nothing more
    exhilirating pointing out the shortcomings of others, is there?
     
    Derk Gwen, Aug 23, 2003
    #8
  9. Puneet

    Greg P. Guest

    "Derk Gwen" <> wrote in message
    news:...
    | The struct tag is pcap_hdr, and would be used
    | struct pcap_hdr C;
    | "pcap" by itself is a global variable name.

    Someone was impatient with the "Send" button =P
     
    Greg P., Aug 23, 2003
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Excluded_Middle

    Pointers to structure and array of structure.

    Excluded_Middle, Oct 24, 2004, in forum: C Programming
    Replies:
    4
    Views:
    791
    Martin Ambuhl
    Oct 26, 2004
  2. Leo Nunez
    Replies:
    3
    Views:
    1,292
    Neil Kurzman
    Feb 9, 2005
  3. Replies:
    4
    Views:
    355
    Richard Tobin
    Nov 15, 2006
  4. Replies:
    2
    Views:
    640
  5. C__chp
    Replies:
    4
    Views:
    542
    Puppet_Sock
    Feb 15, 2008
Loading...

Share This Page