Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > compilation error in structure

Reply
Thread Tools

compilation error in structure

 
 
Puneet
Guest
Posts: n/a
 
      08-22-2003
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;
--
--
--
}
 
Reply With Quote
 
 
 
 
Arthur J. O'Dwyer
Guest
Posts: n/a
 
      08-22-2003

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...+Feeling+Lucky

-Arthur

 
Reply With Quote
 
 
 
 
Mike Wahler
Guest
Posts: n/a
 
      08-22-2003

Puneet <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) m...
> 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




 
Reply With Quote
 
Martin Ambuhl
Guest
Posts: n/a
 
      08-22-2003
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

 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      08-22-2003
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!"

--
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
Derk Gwen
Guest
Posts: n/a
 
      08-22-2003
(E-Mail 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.

--
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?
 
Reply With Quote
 
Derk Gwen
Guest
Posts: n/a
 
      08-22-2003
(E-Mail 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.

--
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?
 
Reply With Quote
 
Derk Gwen
Guest
Posts: n/a
 
      08-22-2003
(E-Mail 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.

--
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?
 
Reply With Quote
 
Greg P.
Guest
Posts: n/a
 
      08-22-2003
"Derk Gwen" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
| 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compilation error with seperate compilation C__chp C++ 4 02-15-2008 03:57 PM
Regarding structure having members under conditional compilation sam_cit@yahoo.co.in C Programming 4 11-15-2006 05:26 PM
Memory allocation in Structure to Structure pra_ramli@rediffmail.com C++ 2 03-09-2006 05:51 AM
Copy String structure "A" to string structure "B" Leo Nunez C Programming 3 02-09-2005 05:14 AM
Pointers to structure and array of structure. Excluded_Middle C Programming 4 10-26-2004 05:39 AM



Advertisments