473,785 Members | 3,032 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

struct declaration query

I'm trying to figure out some code that uses structures, structures, and
more structures...

It's a bit of rat's nest, and I'm having some trouble sorting it all out.

The authors use a lot of the following 'declarations' in the various .h
files:

struct document;
struct document_view;
struct link;
struct session;
struct term_event;
struct terminal;
struct uri;
struct conv_table;

These aren't being used as a part of another structure; they're just
standalone declarations? statements?

I can't quite picture what these do.

What exactly would be the effect of those empty declarations?

Maybe that will help me trace the code....

--Yan
Apr 26 '07 #1
6 1783
In article <13************ *@corp.supernew s.com>
CptDondo <ya*@NsOeSiPnAe Mr.comwrites:
>I'm trying to figure out some code that uses structures, structures, and
more structures...

It's a bit of rat's nest, and I'm having some trouble sorting it all out.

The authors use a lot of the following 'declarations' in the various .h
files:

struct document;
struct document_view;
struct link;
struct session;
struct term_event;
struct terminal;
struct uri;
struct conv_table;

These aren't being used as a part of another structure; they're just
standalone declarations? statements?
They are incomplete types. Usually, the reason for putting those
in is that something in the file declares a pointer to one of them:

struct foo;
void useFoo(foo *fooPtr);

The compiler doesn't need the detail of the struct to deal with a
pointer. Any file that uses the fields inside these structs will
need a complete type defined.

Some libraries use this for encapsulation -- they give you a pointer
that you send back in every call, but no one outside the library
looks inside the struct.
>I can't quite picture what these do.

What exactly would be the effect of those empty declarations?
They tell you, "These types exist and you don't need to know what
is inside them."

--
Drew Lawson | "But the senator, while insisting he was not
dr**@furrfu.com | intoxicated, could not explain his nudity."
Apr 26 '07 #2
CptDondo wrote:
I'm trying to figure out some code that uses structures, structures, and
more structures...

It's a bit of rat's nest, and I'm having some trouble sorting it all out.

The authors use a lot of the following 'declarations' in the various .h
files:

struct document;
struct document_view;
struct link;
struct session;
struct term_event;
struct terminal;
struct uri;
struct conv_table;

These aren't being used as a part of another structure; they're just
standalone declarations? statements?
They are forward declarations, they let the compiler know that these
types exit. You will probably see use of pointers to these as function
parameters or structure members.

--
Ian Collins.
Apr 26 '07 #3
Drew Lawson wrote:
>I can't quite picture what these do.

What exactly would be the effect of those empty declarations?

They tell you, "These types exist and you don't need to know what
is inside them."
OK, thanks. That explains a lot.

The code uses a lot of structures with pointers to other structures, and
macros that define yet more pointers....

The parts I've figured out make sense... But it sure is complicated. :-)

--Yan
Apr 26 '07 #4
On Apr 27, 7:38 am, d...@furrfu.com (Drew Lawson) wrote:
CptDondo <y...@NsOeSiPnA eMr.comwrites:
The authors use a lot of the following 'declarations' in the various .h
files:
struct document;
struct document_view;

They are incomplete types. Usually, the reason for putting those
in is that something in the file declares a pointer to one of them:

struct foo;
void useFoo(foo *fooPtr);
Should read:
void useFoo( struct foo *fooPtr );

If you write this code without the forward declaration, then
'struct foo' gets declared with "prototype scope", meaning
that any subsequent file-scope "struct foo" is actually a
different struct. (Don't ask me why).

Apr 26 '07 #5
In article <11************ **********@u32g 2000prd.googleg roups.com>
Old Wolf <ol*****@inspir e.net.nzwrites:
>On Apr 27, 7:38 am, d...@furrfu.com (Drew Lawson) wrote:
> CptDondo <y...@NsOeSiPnA eMr.comwrites:
>The authors use a lot of the following 'declarations' in the various .h
files:
>struct document;
struct document_view;

They are incomplete types. Usually, the reason for putting those
in is that something in the file declares a pointer to one of them:

struct foo;
void useFoo(foo *fooPtr);

Should read:
void useFoo( struct foo *fooPtr );
Sorry about that.
I'm lazy and hate typing 'struct' all the time, so I have been doing
typedefs for all my structs forever. That seems to have made my
posting a bit sloppy.
>If you write this code without the forward declaration, then
'struct foo' gets declared with "prototype scope", meaning
that any subsequent file-scope "struct foo" is actually a
different struct. (Don't ask me why).
That's a new one. I'm not sure I should try to understand that on
a Friday afternoon.
--
Drew Lawson For it's not the fall, but landing,
dr**@furrfu.com That will alter your social standing
Apr 27 '07 #6
Drew Lawson wrote:
>
In article <11************ **********@u32g 2000prd.googleg roups.com>
Old Wolf <ol*****@inspir e.net.nzwrites:
[...]
If you write this code without the forward declaration, then
'struct foo' gets declared with "prototype scope", meaning
that any subsequent file-scope "struct foo" is actually a
different struct. (Don't ask me why).

That's a new one. I'm not sure I should try to understand that on
a Friday afternoon.
In that case, try wrapping your head around this error message:

usenet.c(14) : warning C4133: 'function' : incompatible types -
from 'struct foobar *' to 'struct foobar *'

Here's the source:

==========
int foo(struct foobar *ptfoo)
{
return 42;
}

struct foobar
{
int a;
int b;
};

int bar(struct foobar *ptbar)
{
return foo(ptbar);
}
==========

When compiling in ANSI mode, the "struct foobar *" type of the
parameter to foo() is not the same "struct foobar *" type of the
parameter to bar().

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer .h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th***** ********@gmail. com>

Apr 27 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
12420
by: Elliot Marks | last post by:
If a struct or its members are passed to a function, must it be declared globally? #include <stdio.h> struct mystruct{ int a; int b; }; int structfunc(struct mystruct foo);
5
3307
by: PCHOME | last post by:
Hello! I am working on dividing a single C file into several files. Now I encounter a problem about the global variables and can not find a way to solve it. All global variables and codes used to be in that single file, that worked OK. But when I divdie that file into several ones, I have many "invalid use of undefined type" errors. The four files are main.c, main.h, readLP.h, and readLP.c. In readLP.h
19
2644
by: Russell Shaw | last post by:
Hi, I have two structs in a header file, and they reference each other, causing a compile error. Is there a standard way to deal with this? typedef struct { ... RtAction *actions; } RtWidget;
6
2692
by: S.Tobias | last post by:
I'm trying to understand how structure type completion works. # A structure or union type of unknown # content (as described in 6.7.2.3) is an incomplete type. It # is completed, for all declarations of that type, by ^^^ # declaring the same structure or union tag with its defining # content later in the same scope. ^^^^^ (6.2.5#23)
14
2310
by: Lane Straatman | last post by:
I would like to write a 'struct'. I have a library that is all but completely inappropriate for this task. So I'm looking for C code that fills in the gaps between: #undef whateverkeithsaysfor99compliance #define whateverkeithsays for99compliance int main(void { struct foo
28
4717
by: Bill | last post by:
Hello All, I am trying to pass a struct to a function. How would that best be accomplished? Thanks, Bill
2
4706
by: Laurent Deniau | last post by:
I would like to know why the following small program does not compile (checked with gcc 4.1.2) and if the compiler behavior is correct: struct A; typedef void (T)(struct A*); void f(void) { struct A { int _; } a; ((T*)0)(&a);
2
281
by: beet | last post by:
Hi all, I tried to declare a c++ struct like following in a header file; I want to include this header file in other files to create and access this struct. ------ 1 #ifndef _SEARCHDATA_H_ 2 #define _SEARCHDATA_H_ 3
10
2245
by: Raman | last post by:
Hi All, Is it valid: struct test{ }; I mean, Can we have a struct containing no members? Is this a an
0
10151
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10092
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3647
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.