473,395 Members | 1,956 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Structure with version ??

Vj
Hi all,

I'm finding some people in my company defining a version number as a
field to some structure.

The sample code goes as follows:

typedef enum _params_ver_ {
UNDEF = 0,
VERSION_1,
VERSION_LAST
} PARAMS_VER;

typdef struct _xyz_ {
PARAMS_VER version;
ULONG info;
} XYZ;

void DoSomething (XYZ asdf);

The argument for the same is as follows:

Suppose another field info2 is added to XYZ, the client using
DoSomething () needn't write any code to intialise the same.

Personally, I think a structure shouldn't have a version. Has anyone,
come across such an I/F ?? Is it recommended??

If the initialisation of the field is generally 0, a memset to the
structure by the client will solve the problem.

R
V

Feb 27 '07 #1
8 2132
On Feb 27, 5:45 am, "Vj" <vijay.rajamanic...@gmail.comwrote:
Hi all,

I'm finding some people in my company defining a version number as a
field to some structure.

The sample code goes as follows:

typedef enum _params_ver_ {
UNDEF = 0,
VERSION_1,
VERSION_LAST

} PARAMS_VER;

typdef struct _xyz_ {
PARAMS_VER version;
ULONG info;

} XYZ;

void DoSomething (XYZ asdf);

The argument for the same is as follows:

Suppose another field info2 is added to XYZ, the client using
DoSomething () needn't write any code to intialise the same.

Personally, I think a structure shouldn't have a version. Has anyone,
come across such an I/F ?? Is it recommended??

If the initialisation of the field is generally 0, a memset to the
structure by the client will solve the problem.

R
V
IMHO, I would use inheritance for this purpose.

For example:
struct base {
data_type dt;
};

struct derived:public struct base {
new_data_type ndt;
};

Now, this way you wouldn't have to worry about changing existing
structure, instead for future releases use the new structure.

Feb 27 '07 #2
Op 27 Feb 2007 07:48:14 -0800 schreef Manish:

<snip>
struct derived:public struct base {
This isn't C. Go left down the hall, past the watercooler and try knocking
at the door of comp.lang.c++.
--
Coos
Feb 27 '07 #3
Manish wrote:
IMHO, I would use inheritance for this purpose.

For example:
struct base {
data_type dt;
};

struct derived:public struct base {
new_data_type ndt;
};
About ten billion people will now point out to you that this
isn't a C++ group. I'm one of them.

--
Chris "electric hedgehog" Dollin
"It's just the beginning we've seen" - Colosseum, /Tomorrow's Blues/

Feb 27 '07 #4
On Feb 27, 11:07 am, Chris Dollin <chris.dol...@hp.comwrote:
Manish wrote:
IMHO, I would use inheritance for this purpose.
For example:
struct base {
data_type dt;
};
struct derived:public struct base {
new_data_type ndt;
};

About ten billion people will now point out to you that this
isn't a C++ group. I'm one of them.

--
Chris "electric hedgehog" Dollin
"It's just the beginning we've seen" - Colosseum, /Tomorrow's Blues/
Yeah, I also thought about it just after hitting the send button.

Feb 27 '07 #5
Vj wrote On 02/27/07 05:45,:
Hi all,

I'm finding some people in my company defining a version number as a
field to some structure.

The sample code goes as follows:

typedef enum _params_ver_ {
UNDEF = 0,
VERSION_1,
VERSION_LAST
} PARAMS_VER;

typdef struct _xyz_ {
PARAMS_VER version;
ULONG info;
} XYZ;
Sooner or later, the evil habit of starting identifiers
with underscores will rise up and bite you in the underwear.
See http://www.oakroadsystems.com/tech/c-predef.htm; it's a
bit out of date (in fact, the URL links to a disclaimer which
in turn links to the document), but worth reading.
void DoSomething (XYZ asdf);

The argument for the same is as follows:

Suppose another field info2 is added to XYZ, the client using
DoSomething () needn't write any code to intialise the same.
I think you've slightly misstated the situation, or else
you've glossed over quite a few devilish details. No matter.
Personally, I think a structure shouldn't have a version. Has anyone,
come across such an I/F ?? Is it recommended??
If you can recompile all the source when you change a
struct definition there's not much benefit to versioning:
there is only one version, the current version, and that's
that. But sometimes there are situations where you cannot
recompile everything, or where prior versions of the struct
have been salted away in files and other places where the
compiler can't touch them. In such cases a version number
can be part of the solution -- it doesn't solve very much
all by its lonesome, but it can provide the foothold the
bulk of the solution requires.
If the initialisation of the field is generally 0, a memset to the
structure by the client will solve the problem.
(1) "Maybe" and (2) "It depends what you think `the
problem' is."

--
Er*********@sun.com
Feb 27 '07 #6
Manish wrote:
On Feb 27, 11:07 am, Chris Dollin <chris.dol...@hp.comwrote:
>Manish wrote:
>>IMHO, I would use inheritance for this purpose.
For example:
struct base {
data_type dt;
};
struct derived:public struct base {
new_data_type ndt;
};
About ten billion people will now point out to you that this
isn't a C++ group. I'm one of them.

--
Chris "electric hedgehog" Dollin
"It's just the beginning we've seen" - Colosseum, /Tomorrow's Blues/

Yeah, I also thought about it just after hitting the send button.
Still, this is probably the best approach to manage version on the long
time. To implement OO features in C, you may have a look to:

http://www.cern.ch/laurent.deniau/oopc.html#OOC-S

Which was specifically written for C programmers.

a+, ld.
Feb 27 '07 #7
Vj wrote:
I'm finding some people in my company defining a version number as a
field to some structure.

The sample code goes as follows:

typedef enum _params_ver_ {
UNDEF = 0,
VERSION_1,
VERSION_LAST
} PARAMS_VER;

typdef struct _xyz_ {
PARAMS_VER version;
ULONG info;
} XYZ;

void DoSomething (XYZ asdf);

The argument for the same is as follows:

Suppose another field info2 is added to XYZ, the client using
DoSomething () needn't write any code to intialise the same.

Personally, I think a structure shouldn't have a version. Has anyone,
come across such an I/F ?? Is it recommended??
it might make sort of sense is the structure is being used to
communicate between different programs. This is, of course,
fraught with difficulties.

don't do it between disparate platforms (this could include
compiler version).

If the initialisation of the field is generally 0, a memset to the
structure by the client will solve the problem.

--
Nick Keighley

Feb 28 '07 #8
Vj wrote:
Hi all,

I'm finding some people in my company defining a version number as a
field to some structure.

The sample code goes as follows:

typedef enum _params_ver_ {
UNDEF = 0,
VERSION_1,
VERSION_LAST
} PARAMS_VER;

typdef struct _xyz_ {
PARAMS_VER version;
ULONG info;
} XYZ;

void DoSomething (XYZ asdf);

The argument for the same is as follows:

Suppose another field info2 is added to XYZ, the client using
DoSomething () needn't write any code to intialise the same.

Personally, I think a structure shouldn't have a version. Has anyone,
come across such an I/F ?? Is it recommended??
I use a similar versioning scheme for some public structures shared by
different dynamically loadable libraries.

#define MEGAIMAGE_HEADER_VERSION 3
struct megaimage_header {
int version; /*just in case we add features later*/
int width;
int height;
size_t imagesize;
};
/* image bytes follow the structure */

Then the various compiled libraries run a test like this:

if (h->version != MEGAIMAGE_HEADER_VERSION) {
/* report error */
/* exit if needed */
}

Why did I start doing that you may ask? I found that I was sometimes
incrementally updating the libraries for various programs that load the
libraries dynamically, and during testing bugs were showing up that were
caused by the binary incompatibilities. So, this makes sure that they
are updated together in a binary-compatible way -- assuming I remember
to increase the MEGAIMAGE_HEADER_VERSION when making incompatible
changes. :)

-George

Mar 1 '07 #9

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

Similar topics

1
by: sreak | last post by:
Need to find the cause of the following error: The sample code goes as follows:( file name version.cpp ) #include <iostream> struct version { int val; }; int main()
0
by: Oliver Elphick | last post by:
The attached proposal is written primarily for Debian. Its motivation is that the current package upgrade process is pretty flaky and also that the current packaging does not really provide for...
5
by: oNLINE bUDDY | last post by:
How can you reverse a many-to-many XML structure between 2 tags? Lets say we have a books/author XML file. A book can have many authors. <book1> <Author1> </Author1> </book1>
5
by: brett valjalo | last post by:
Hey Gang! SORRY ABOUT THE LENGTH! Nice to see some of the same faces around this place from way back when ... Whatta buncha CDMA addicts some o' y'all are ;) Don't get me wrong, I...
29
by: Glen | last post by:
Is it possible to write a structure to a file in c...as in c++...?? is it using fwrite?? thanx glen
8
by: Charles Law | last post by:
Can anyone suggest how I would marshal a variable length structure back from an API call. Specifically, I am looking at the WaitForDebugEvent function, which returns a DEBUG_EVENT structure. ...
0
by: michael.Zlaugotnis | last post by:
I've got a problem with the following C++ Structur in Vb.Net. typedef struct SStateInfo { int Version; // Version der Struktur char Name; // Bundeslandname char Shrt; // Kuerzel des...
11
by: aaragon | last post by:
Hi everyone. I'm trying to write a class with policy based design (Alexandrescu's Modern C++ Design). I'm not a programmer but an engineer so this is kind of hard for me. Through the use of...
5
by: =?Utf-8?B?QXlrdXQgRXJnaW4=?= | last post by:
Hi Willy, Thank you very much for your work. C++ code doesnot make any serialization. So at runtime C# code gives an serialization error at "msg_file_s sa = (msg_file_s) bf.Deserialize(ms);"...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...
0
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...

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.