What does it mean ?

R

ranjeet.gupta

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
 
J

Jaspreet

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

Eric Sosman

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*'.
 
F

forayer

Eric said:
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
 
R

ranjeet.gupta

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


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


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"
 
F

forayer

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]
 
E

Eric Sosman

forayer said:
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).
 
F

Fred L. Kleinschmidt

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 <[email protected]>
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: <[email protected]>
Sender: (e-mail address removed) (Boeing NNTP News Access)
Content-Transfer-Encoding: 7bit
Organization: The Boeing Company
X-Accept-Language: en
References: <2bque.17994$FP2.649@lakeread03> <[email protected]>
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 said:
In this one from 2000 Skippy seems to have hijacked a 1979 Honda.
Nice taste. :cool:
http://170.164.50.60/openaccess/civ...LL+CLAIMS+MOTION+HEARING+RE:+TURN+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.
 
E

Eric Sosman

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

ranjeet.gupta

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




 
R

ranjeet.gupta

Eric said:
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




 
F

forayer

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.
Please remove the above signature in your posts. Its Eric's. ;-)

cheers,
forayer
 
R

ranjeet.gupta

forayer said:
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.
 
M

Mark

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'.
:)
 

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,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top