473,503 Members | 1,739 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reason for the Format

Dear All

As I was going through the code, I find the below piece of code,

#define FILEMAPPING \
char *data; \
int size; \
char *position; \
int (*open)(struct FileMapping *self, const char *filename ); \
int (*close) (struct FileMapping *self ); \
int (*destroy) (struct FileMapping *self ); \
int (*isYourFile)(struct FileMapping *self, const char *filename, u32
*outSameFile );

typedef struct FileMapping
{
FILEMAPPING
} FileMapping, *FileMapping;

Over above they have declared the Macro Named FILEMAPPING but I am not
able to understand what does it really mean ?, they have declared the
macro which is going to be replaced in the structure FileMapping, But
why they want to go in the above format. ?

its is just same as some what below code..

#define LINKLIST int data; struct node *link;

strcut node {

LINKLIST;
};
Thanks in Advance
Ranjeet

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

As I was going through the code, I find the below piece of code,

#define FILEMAPPING \
char *data; \
int size; \
char *position; \
int (*open)(struct FileMapping *self, const char *filename ); \
int (*close) (struct FileMapping *self ); \
int (*destroy) (struct FileMapping *self ); \
int (*isYourFile)(struct FileMapping *self, const char *filename, u32
*outSameFile );

typedef struct FileMapping
{
FILEMAPPING
} FileMapping, *FileMapping;

Over above they have declared the Macro Named FILEMAPPING but I am not
able to understand what does it really mean ?, they have declared the
macro which is going to be replaced in the structure FileMapping, But
why they want to go in the above format. ?

its is just same as some what below code..

#define LINKLIST int data; struct node *link;

strcut node {

LINKLIST;
};
Thanks in Advance
Ranjeet


Ranjeet I guess it just for better readiblity and code organisation so
that tomorrow if any other developer comes across this code he is able
to understand it better.

Imagine having all the variable and function decl. on the same line and
then compare it with seperate variable decl on different line and then
function decl. on different lines.

Nov 15 '05 #2
ra***********@gmail.com wrote:
# Dear All
#
# As I was going through the code, I find the below piece of code,
#
# #define FILEMAPPING \
# char *data; \
# int size; \
# char *position; \
# int (*open)(struct FileMapping *self, const char *filename ); \
# int (*close) (struct FileMapping *self ); \
# int (*destroy) (struct FileMapping *self ); \
# int (*isYourFile)(struct FileMapping *self, const char *filename, u32
# *outSameFile );
#
# typedef struct FileMapping
# {
# FILEMAPPING
# } FileMapping, *FileMapping;
#
# Over above they have declared the Macro Named FILEMAPPING but I am not
# able to understand what does it really mean ?, they have declared the
# macro which is going to be replaced in the structure FileMapping, But
# why they want to go in the above format. ?

Subtyping. If you want a FileMapping object, use struct {FILEMAPPING}. If
you want to derive a subtype that allows the segment length to be set,
#define EXTENDEDABLE_FILEMAPPING \
FILEMAPPING \
int (*setlength)(struct ExtendableFileMapping *self,long long);
typedef struct ExtendableFileMapping {
EXTENDEDABLE_FILEMAPPING
} ExtendableFileMapping;

If I remember aright you are guarenteed that if
ExtendableFileMapping *e = (plugh);
FileMapping *m = (FileMapping*)e;
then
&(m->data) == &(e->data)
&(m->size) == &(e->size)
. . .
&(m->isYourFile) == &(e->isYourFile)
so that you can cast a subtyped object to a supertype and access supertype
fields and methods either way.

The less tricky way to do this is
/*supertype*/
typedef struct FileMapping
char *data;
int size;
char *position;
int (*open)(struct FileMapping *self, const char *filename );
int (*close) (struct FileMapping *self );
int (*destroy) (struct FileMapping *self );
int (*isYourFile)(struct FileMapping *self, const char *filename, u32
*outSameFile );
} FileMapping;

/*subtype*/
typedef struct ExtendableFileMapping
FileMapping super;
int (*setlength)(struct ExtendableFileMapping *self,long long);
} ExtendableFileMapping;

ExtendableFileMapping *e = (plugh);
FileMapping *m = &(e->super);

--
SM Ryan http://www.rawbw.com/~wyrmwif/
I hope it feels so good to be right. There's nothing more
exhilirating pointing out the shortcomings of others, is there?
Nov 15 '05 #3
SM Ryan wrote:
Ranjeet Gupta wrote:
# Dear All
#
[...]
--
SM Ryan http://www.rawbw.com/~wyrmwif/
I hope it feels so good to be right. There's nothing more
exhilirating pointing out the shortcomings of others, is there?


Why do you use a non-standard quote character?
('#' instead of '>')

Your signature delimiter is incorrect.
(It should be DASH-DASH-SPACE-NEWLINE)

Is "exhilarating" misspelled on purpose?

--
Regards, Grumble
Nov 15 '05 #4
Grumble <de*****@kma.eu.org> wrote:
# SM Ryan wrote:
#
# > Ranjeet Gupta wrote:
# > # Dear All
# > #
# > [...]
# > --
# > SM Ryan http://www.rawbw.com/~wyrmwif/
# > I hope it feels so good to be right. There's nothing more
# > exhilirating pointing out the shortcomings of others, is there?
#
# Why do you use a non-standard quote character?
# ('#' instead of '>')

So I can look at post and see if it's a reply to me by just looking
at the body.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
The little stoner's got a point.
Nov 15 '05 #5


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

As I was going through the code, I find the below piece of code,

#define FILEMAPPING \
char *data; \
int size; \
char *position; \
int (*open)(struct FileMapping *self, const char *filename ); \
int (*close) (struct FileMapping *self ); \
int (*destroy) (struct FileMapping *self ); \
int (*isYourFile)(struct FileMapping *self, const char *filename, u32
*outSameFile );

typedef struct FileMapping
{
FILEMAPPING
} FileMapping, *FileMapping;

Over above they have declared the Macro Named FILEMAPPING but I am not
able to understand what does it really mean ?, they have declared the
macro which is going to be replaced in the structure FileMapping, But
why they want to go in the above format. ?

SM Ryan's explanation of subtyping makes sense, but...yuck. This is
one of those cases where you'd be better served using a language that
directly supports derived types (C++, Java, etc.).

One trick I saw in some old MacOS code was known as piggybacking.
People would create their own document types by starting with the base
Window type and adding attributes for their particular needs:

struct MyDocument {
Window wind;
char *docName;
char *docAuthor;
/* additional attributes as necessary */
};

Since a pointer to a struct is also necessarily a pointer to the first
element, people could pass a pointer to objects of type MyDocument to
the Toolbox routines where a pointer to a Window type was expected.
That way data that needed to be associated with a specific window could
be stored with that window. Simplified data management somewhat.

The tradeoff was that you wound up doing some ugly casting acrobatics.

its is just same as some what below code..

#define LINKLIST int data; struct node *link;

strcut node {

LINKLIST;
};
Thanks in Advance
Ranjeet


Nov 15 '05 #6
jo*******@my-deja.com wrote:

# One trick I saw in some old MacOS code was known as piggybacking.
# People would create their own document types by starting with the base
# Window type and adding attributes for their particular needs:

# Since a pointer to a struct is also necessarily a pointer to the first
# element, people could pass a pointer to objects of type MyDocument to
# the Toolbox routines where a pointer to a Window type was expected.
# That way data that needed to be associated with a specific window could
# be stored with that window. Simplified data management somewhat.

That's essentially what single inheritance languages like Smalltalk do
behind the scenes. The one difference is instead of packing data and
function pointers together, they pack the data and a pointer to a
struct of function pointers shared by every object in the same class.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
I think that's kinda of personal; I don't think I should answer that.
Nov 15 '05 #7
In article <11*************@corp.supernews.com>
SM Ryan <wy*****@tango-sierra-oscar-foxtrot-tango.fake.org> wrote:
[I use something other than the usual ">" quote character] So [that]
I can look at post and see if it's a reply to me by just looking
at the body.


I believe there is a small flaw in this reasoning. :-)
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Nov 15 '05 #8

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

Similar topics

15
42977
by: Simon Brooke | last post by:
I'm investigating a bug a customer has reported in our database abstraction layer, and it's making me very unhappy. Brief summary: I have a database abstraction layer which is intended to...
10
2661
by: sp0 | last post by:
Is there a reason why to make mix numbers improper when adding? It seems when subtracting and adding, adding a subtracting the whole numbers and fraction parts should be sufficient? what'ch think
3
19216
by: stevek | last post by:
How do I format an integer. Add commas. 1234565 1,234,565 TIA
6
31128
by: Dario Di Bella | last post by:
Hi all, we have the following urgent issue affecting our development team. Initially we had one particular workstation that failed executing queries on a DB2 database, raising an invalid date...
11
5918
by: Grumble | last post by:
Hello, I have the following structure: struct foo { char *format; /* format string to be used with printf() */ int nparm; /* number of %d specifiers in the format string */ /* 0 <= nparm <=...
4
1623
by: David Morris | last post by:
Hi Could somebody please explain what the following line of code means String.Format("{0}\{1}.{2:00}", C:\, myfile.txt, 1 It's actually the first argument that I don't understand. What is...
37
2106
by: Greg | last post by:
Except for legacy or non-.NET applications, is there any reason to use VC++ anymore? It seems that for .NET applications, there would be no reason to choose C++ over C# since C# is faster to...
1
939
by: =?Utf-8?B?Y2xhcmE=?= | last post by:
Hi all, I just retrieve a date field into a texbox, but the date has changed when it is read from database. The database is designed by others,I not sure whether there is something wrong in...
4
2516
by: jonathan184 | last post by:
Hi I have a perl script, basically what it is suppose to do is check a folder with files. Now the files are checked using a timestamp with the command ls -l so the timestamp in this format is...
0
7087
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7281
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7334
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...
1
6993
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...
0
5579
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3168
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...
0
1514
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 ...
1
737
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.