468,719 Members | 1,705 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,719 developers. It's quick & easy.

What does it mean ?

Dear All

What does exactly below code means

struct File
{
void* data;
};
typedef struct File File;
typedef File* fl;

And thanks to Jaspreet and SM Ryan for the clarifying my previous
querry.

Thanks In advance
Ranjeet

Nov 15 '05 #1
13 1917
ra***********@gmail.com wrote:
Dear All

What does exactly below code means

struct File
{
void* data;
Declaring a pointer of type void so that it can then be typecast to any
data type. Consider this as a Joker in a game of cards. You are not
sure right now what all type could the data be.
};
typedef struct File File;
typedef File* fl;

And thanks to Jaspreet and SM Ryan for the clarifying my previous
querry.

Thanks In advance
Ranjeet


Nov 15 '05 #2


ra***********@gmail.com wrote:
Dear All

What does exactly below code means

struct File
{
void* data;
};
This declares `struct File' as the type of a struct that
contains one element named `data' whose type is "pointer to
`void'."
typedef struct File File;
This declares `File' as an alias for `struct File'.
typedef File* fl;


This declares `fl' as an alias for `File*', that is,
as an alias for `struct File*'.

--
Er*********@sun.com

Nov 15 '05 #3
Eric Sosman wrote:
ra***********@gmail.com wrote:
Dear All

What does exactly below code means

struct File
{
void* data;
};


This declares `struct File' as the type of a struct that
contains one element named `data' whose type is "pointer to
`void'."

A void * pointer isn't a pointer to a void object, its a pointer to any
object. Its just that you dont know what type of object its pointing
to! A discussion on this topic was already carried out in the thread:
"void *malloc(size_t num_bytes);" started by Alawna on Jun 19. (This
particular discussion appears towards the end of the thread). Besides,
what do you mean by 'pointer to void'?

forayer

Nov 15 '05 #4


Eric Sosman wrote:
ra***********@gmail.com wrote:
Dear All

What does exactly below code means

struct File
{
void* data;
};
This declares `struct File' as the type of a struct that
contains one element named `data' whose type is "pointer to
`void'."
typedef struct File File;


This declares `File' as an alias for `struct File'.
typedef File* fl;


This declares `fl' as an alias for `File*', that is,
as an alias for `struct File*'.


Eric Do you mean that "fl" as an alias of the File Pointer,
menas that it is alias to the strcut File *(pointer),

Pointer to the file which is of struct type is named as "fl"


--
Er*********@sun.com


Nov 15 '05 #5
ranjeet.gu...@gmail.com wrote:
Eric Sosman wrote:
typedef struct File File;


This declares `File' as an alias for `struct File'.
typedef File* fl;


This declares `fl' as an alias for `File*', that is,
as an alias for `struct File*'.


Eric Do you mean that "fl" as an alias of the File Pointer,
menas that it is alias to the strcut File *(pointer),

Pointer to the file which is of struct type is named as "fl"

This should make it a bit more clearer (given the typedefs):

File f; // is equivalent to declaring it as "struct File f"

f1 g; // is equivalent to declaring it as "File *g"
// but since declaring "File <anything>" is
// similar to declaring it as "struct File <anything>",
// "f1 g" is also equivalent to "struct File *g"

Hope this helps.

cheers,
forayer]

Nov 15 '05 #6


forayer wrote:
Eric Sosman wrote:
ra***********@gmail.com wrote:
Dear All

What does exactly below code means

struct File
{
void* data;
};
This declares `struct File' as the type of a struct that
contains one element named `data' whose type is "pointer to
`void'."


A void * pointer isn't a pointer to a void object,


I did not say that it was. There is no such thing as
a `void' object.
its a pointer to any
object. Its just that you dont know what type of object its pointing
to! A discussion on this topic was already carried out in the thread:
"void *malloc(size_t num_bytes);" started by Alawna on Jun 19. (This
particular discussion appears towards the end of the thread). Besides,
what do you mean by 'pointer to void'?


`void' is a type. It happens to be an incomplete type
with the special property that it can never be completed.

Given any type T, complete or incomplete, it is always
possible to derive a new "pointer to T" type denoted `T*'.
(One may eventually encounter compiler limitations on the
number of levels of indirection permitted -- it might not
be possible to use an `int******************************',
for example -- but these are implementation artifacts and
not characteristics of the language.) In particular, there
is a type `void' and so it is possible to derive a "pointer
to `void'" type denoted `void*'.

The Standard contains a few special guarantees about the
`void*' type, and these make it useful as a sort of "type-
blind" pointer. You can't do much with a `void*' as it
stands (you can compare it to other pointer values, but
that's about it), but you can convert it to some other data
pointer type and make use of the converted value (if valid).

--
Er*********@sun.com

Nov 15 '05 #7


ra***********@gmail.com wrote:

Eric Sosman wrote:
ra***********@gmail.com wrote:
Dear All

What does exactly below code means

struct File
{
void* data;
};


This declares `struct File' as the type of a struct that
contains one element named `data' whose type is "pointer to
`void'."

typedef struct File File;


This declares `File' as an alias for `struct File'.

typedef File* fl;


This declares `fl' as an alias for `File*', that is,
as an alias for `struct File*'.

Eric Do you mean that "fl" as an alias of the File Pointer,
menas that it is alias to the strcut File *(pointer),

Pointer to the file which is of struct type is named as "fl"


Yes. Given these definitions, all the following
fragments are equivalent:

struct File s;
struct File *p = &s;

File s;
File *p = &s;

File s;
fl p = &s;

struct File s;
fl p = &s;

--
Er*********@sun.com

Nov 15 '05 #8


ra***********@gmail.com wrote:

Dear All

What does exactly below code means

struct File
{
void* data;
};
typedef struct File File;
typedef File* fl;

And thanks to Jaspreet and SM Ryan for the clarifying my previous
querry.

Thanks In advance
Ranjeet
Compare with this structuring, which is easier to read and does the same
thing:

typedef struct File {
void *data;
} File, *fl;

The type of "File" is "struct File".
The type of "fl" is "pointer to a 'struct File'"

--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Common User Interface Services
M/S 2R-94 (206)544-5225
#! rnews 1533
Xref: xyzzy rec.models.rockets:559284
Newsgroups: rec.models.rockets
Path: xyzzy!nntp
From: WallaceF <fr*********@boe.com>
Subject: Re: Court records are SUCH fun....
X-Nntp-Posting-Host: pex003155.se.nos.boeing.com
Content-Type: text/plain; charset=us-ascii
Message-ID: <42***************@boe.com>
Sender: nn**@news.boeing.com (Boeing NNTP News Access)
Content-Transfer-Encoding: 7bit
Organization: The Boeing Company
X-Accept-Language: en
References: <2bque.17994$FP2.649@lakeread03> <d1********************************@4ax.com>
Mime-Version: 1.0
Date: Thu, 23 Jun 2005 15:10:17 GMT
X-Mailer: Mozilla 4.79 [en]C-CCK-MCD Boeing Kit (Windows NT 5.0; U)

Phil Stein wrote:
On Wed, 22 Jun 2005 22:40:39 -0500, Kevin Trojanowski
<tr**@nospam.cox.net> wrote:
http://170.164.50.60/openaccess/crim...nbr=75199&dsn=

Or, for those of you who like 'em shorter....

http://tinyurl.com/d9m62

-Kevin


In this one from 2000 Skippy seems to have hijacked a 1979 Honda.
Nice taste. 8-)
http://170.164.50.60/openaccess/civi...RN+OVER+ORDER+

Hey Jerry, How's biz? If it's good, maybe you can move up to an 85
model.

Shure hope JI involvement with Xavien does not cause problems for a
manufacture of some preaty darn good products.
Nov 15 '05 #9


Eric Sosman wrote:
ra***********@gmail.com wrote:

Eric Sosman wrote:
ra***********@gmail.com wrote:

Dear All

What does exactly below code means

struct File
{
void* data;
};

This declares `struct File' as the type of a struct that
contains one element named `data' whose type is "pointer to
`void'."
typedef struct File File;

This declares `File' as an alias for `struct File'.
typedef File* fl;

This declares `fl' as an alias for `File*', that is,
as an alias for `struct File*'.

Eric Do you mean that "fl" as an alias of the File Pointer,
menas that it is alias to the strcut File *(pointer),

Pointer to the file which is of struct type is named as "fl"


Yes. Given these definitions, all the following
fragments are equivalent:

struct File s;
struct File *p = &s;

File s;
File *p = &s;

File s;
fl p = &s;

struct File s;
fl p = &s;


Thanks to you forver and eric, I got cleared, But have one doubt
in other issue i.e

Below is the code which I find in the Source code
struct FileRecord
{
void *data;
};
typedef struct FileRecord FileRecord;
typedef FileRecord* flReader;

Now I think the above is same as what i understood so I am
writting the code.

typedef struct
{
void *data;
}FileRecord;

typedef FileRecord* flReader;

IF above is correct then it means I understood correctly,
Please bear with me as I dont have the compiler at present.


--
Er*********@sun.com


Nov 15 '05 #10


Eric Sosman wrote:
ra***********@gmail.com wrote:

Eric Sosman wrote:
ra***********@gmail.com wrote:

Dear All

What does exactly below code means

struct File
{
void* data;
};

This declares `struct File' as the type of a struct that
contains one element named `data' whose type is "pointer to
`void'."
typedef struct File File;

This declares `File' as an alias for `struct File'.
typedef File* fl;

This declares `fl' as an alias for `File*', that is,
as an alias for `struct File*'.

Eric Do you mean that "fl" as an alias of the File Pointer,
menas that it is alias to the strcut File *(pointer),

Pointer to the file which is of struct type is named as "fl"


Yes. Given these definitions, all the following
fragments are equivalent:

struct File s;
struct File *p = &s;

File s;
File *p = &s;

File s;
fl p = &s;

struct File s;
fl p = &s;


Thanks to you forver and eric, I got cleared, But have one doubt
in other issue i.e

Below is the code which I find in the Source code
struct FileRecord
{
void *data;
};
typedef struct FileRecord FileRecord;
typedef FileRecord* flReader;

Now I think the above is same as what i understood so I am
writting the code.

typedef struct
{
void *data;
}FileRecord;

typedef FileRecord* flReader;

IF above is correct then it means I understood correctly,
Please bear with me as I dont have the compiler at present.
So I cant check it my understanding.
Thanks


--
Er*********@sun.com


Nov 15 '05 #11
ra***********@gmail.com wrote:

Below is the code which I find in the Source code
struct FileRecord
{
void *data;
};
typedef struct FileRecord FileRecord;
typedef FileRecord* flReader;

Now I think the above is same as what i understood so I am
writting the code.

typedef struct
{
void *data;
}FileRecord;

typedef FileRecord* flReader;

IF above is correct then it means I understood correctly,
Please bear with me as I dont have the compiler at present.
Yes, it is correct. But the struct is untagged i.e. no more "struct
FileRecord" declarations. 'typedef'ing structs is used to ease up
writing effort, but don't over do it, or you will end up not
understanding the code at all.
--
Er*********@sun.com

Please remove the above signature in your posts. Its Eric's. ;-)

cheers,
forayer
Nov 15 '05 #12


forayer wrote:
ra***********@gmail.com wrote:

Below is the code which I find in the Source code
struct FileRecord
{
void *data;
};
typedef struct FileRecord FileRecord;
typedef FileRecord* flReader;

Now I think the above is same as what i understood so I am
writting the code.

typedef struct
{
void *data;
}FileRecord;

typedef FileRecord* flReader;

IF above is correct then it means I understood correctly,
Please bear with me as I dont have the compiler at present.
Yes, it is correct. But the struct is untagged i.e. no more "struct
FileRecord" declarations. 'typedef'ing structs is used to ease up
writing effort, but don't over do it, or you will end up not
understanding the code at all.


Thanks Forayer, I got the idea behind it and the use of it,
and got clarified by you all.
--
Er*********@sun.com

Please remove the above signature in your posts. Its Eric's. ;-)

cheers,
forayer


Nov 15 '05 #13
<ra***********@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Dear All

What does exactly below code means

struct File
{
void* data;
};
typedef struct File File;
typedef File* fl;

And thanks to Jaspreet and SM Ryan for the clarifying my previous
querry.

Thanks In advance
Ranjeet


Very complicated, but in a nutshell - it means:
U.S. companies should stop 'outsourcing'.
:-)
Nov 15 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Jukka K. Korpela | last post: by
86 posts views Thread by Michael Kalina | last post: by
2 posts views Thread by Steve Richter | last post: by
121 posts views Thread by typingcat | last post: by
51 posts views Thread by jacob navia | last post: by
1 post views Thread by Frank Rizzo | last post: by
13 posts views Thread by Jason Huang | last post: by
9 posts views Thread by JoeC | last post: by
1 post views Thread by CARIGAR | last post: by
1 post views Thread by Oskars | last post: by
9 posts views Thread by bryonone | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.