Archived

This topic is now archived and is closed to further replies.

elis-cool

My Own File Format....

Recommended Posts

elis-cool    271
Well I had a go, I know some of the basics... eg my header has varous info including total ''lumps'' of data in the file and the offset of the datatable about where the ''lumps'' are located and it has to be of a fixed size... but Im haveing a bit of trouble so does anyone know of some tutorials, there is one on GDnet but it had to much stuff in it and quite frankly I dont know what this means...
typedef struct Name
{
   ...
}object, *pObject; 
So do you know some more... CEO Plunder Studios

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
quote:
Original post by elis-cool
I dont know what this means...
typedef struct Name
{
...
}object, *pObject;


Oh come on! I''m sure you can figure it out!

Hint: There is no C/C++ book in existence that doesn''t explain structs much much better than any forum post ever could.

Another hint: MSDN is free.

Share this post


Link to post
Share on other sites
JungleJim    122
quote:
Original post by Gabriel Fleseriu
That means: object is a synonim for the structure Name, *pObject is a synonim for the pointer to a structure Name


Actually, that''s not entirely correct.

''Name'' is a typedef for a nameless structure. ''object'' is an instance of the structure (i.e. variable of type ''Name''), and pObject is a pointer to the structure.

Note that in C++ the typedef isn''t necessary:

struct Name {
...
} object, *pObject;

Share this post


Link to post
Share on other sites
Sandman    2210
quote:
Original post by JungleJim
Actually, that's not entirely correct.



Actually, Gabriel is correct.

It defines a structure called struct Name (or just Name in C++) and typedefs object as synonym for struct Name and pObject as a pointer to a struct Name .





[edited by - Sandman on May 2, 2002 8:57:08 AM]

Share this post


Link to post
Share on other sites
JungleJim    122
quote:
Original post by Sandman
Actually, Gabriel is correct.

It defines a structure called struct Name (or just Name in C++) and typedefs object as synonym for struct Name and pObject as a pointer to a struct Name .


Doh, you''re right! My bad...

Share this post


Link to post
Share on other sites
JungleJim    122
quote:
Original post by elis-cool
It was just the typedef that got me...
So insteed of: Name obj1; you could go: Object obj2; ???


It depends. If you program in C++, you do not need a typedef when declaring structs:

// This is C++
struct Object {
...
};

Object* pObject;

But if you use (ANSI) C, then a typedef makes things easier, because the full type of a struct is ''struct Object'', instead of just ''Object'':

/* This is (ANSI) C */
struct Object {
...
};

struct Object* pObject;

If you use a typedef, you can use ''Object'' as the type:

/* This is (ANSI) C */
typedef struct _Object {
...
} Object;

Object* pObject;

In this last code example, the full type name of the struct is ''struct _Object''. ''Object'' is a typedef for this ''struct _Object'', which saves typing 7 characters

Share this post


Link to post
Share on other sites
Sandman    2210
quote:
Original post by elis-cool
It was just the typedef that got me...
So insteed of: Name obj1; you could go: Object obj2; ???



Basically yes.

In C, if you define a structure like:


// METHOD A
struct object
{
// blah
}


then in order to create an instance of that structure you need to use the following syntax....


struct object myObject; // create an instance of an object
struct object* pMyObject; // create a pointer to an object


However by using typedef like so:


// METHOD B
typedef struct
{
// blah
}object, *pObject;


you can drop the annoying ''struct'' syntax when you create instances:


object myObject; // create an instance of an object
pObject pMyObject;// create a pointer to an object


The rules change slightly under C++, so that objects declared using Method A don''t need the struct keyword when you declare instances. However, you still need to use a typedef if you want to create a synonym for a pointer type:


typedef struct object
{
}*pObject;


Thats either cleared things up, or confused you completely. I''d recommend learning about typedef, used well it will make your code cleaner and easier to read.

Share this post


Link to post
Share on other sites