compilation error in structure

P

Puneet

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;
 
A

Arthur J. O'Dwyer

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
 
M

Mike Wahler

Puneet said:
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
 
M

Martin Ambuhl

Puneet said:
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.


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;'.
 
E

Eric Sosman

Puneet said:
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!"
 
D

Derk Gwen

(e-mail address removed) (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.
 
D

Derk Gwen

(e-mail address removed) (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.
 
D

Derk Gwen

(e-mail address removed) (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.
 
G

Greg P.

| 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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top