By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,146 Members | 1,820 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,146 IT Pros & Developers. It's quick & easy.

rewriting typedef to define

P: n/a
I need to rewrite some typedef to #define.

For instance I rewrote

typedef void* handle
to
#define handle void*

But I saw for instance another typedef in my code which I don't
understand, which is

typedef const char* const* attrListPtr;

First I don't really understand this typedef and then I was wondering
how this should be rewritten using #define

I also have another typedef which I do understand. It is used for
function aliasing. But I was wondering how and if it is possible in
such a case also to replace the typedef by using #define.

For instance how would you rewrite:

typedef double (*Addition)(double value1, double value2);

??

Many thanks in advance,

rr
Jun 27 '08 #1
Share this Question
Share on Google+
6 Replies


P: n/a
* wo*********@yahoo.com:
I need to rewrite some typedef to #define.
Most probably you don't.

I have never needed that.

You should avoid macros (except where really needed such as header guards)
because they don't respect scopes and namespaces and have counter-intuitive effects.

For instance I rewrote

typedef void* handle
And most probably you don't need void* pointers.

Those are for experienced folks doing low-level things.

You, on the other hand, are not experienced (otherwise you wouldn't have asked),
and presumably you're not doing low-level things either.

to
#define handle void*
Thus breaking a lot of code where the word "handle" occurs.

But I saw for instance another typedef in my code which I don't
understand, which is

typedef const char* const* attrListPtr;
You have written ("my code") something you don't understand.

Try to write only things you understand.

Of course when using copy-and-modify techqnique to make interesting or useful
programs, you cannot totally avoid including code you don't yet understand.
First I don't really understand this typedef and then I was wondering
how this should be rewritten using #define
Don't.

I also have another typedef which I do understand. It is used for
function aliasing. But I was wondering how and if it is possible in
such a case also to replace the typedef by using #define.
Don't.

For instance how would you rewrite:

typedef double (*Addition)(double value1, double value2);
One wouldn't.
Cheers, & hth.,

- Alf
Jun 27 '08 #2

P: n/a
On 4月13日, 上午12时36分, "wongjoek...@yahoo.com" <wongjoek...@yahoo.com>
wrote:
I need to rewrite some typedef to #define.

For instance I rewrote

typedef void* handle
to
#define handle void*
This should cause problem.
You'd better not do like this.
>
But I saw for instance another typedef in my code which I don't
understand, which is

typedef const char* const* attrListPtr;
attrListPtr is a pointer, point to a const pointer variable, which
point to a const char (array).
You can understand it like this:
typedef const char* (const(* attrListPtr));
and I think the following typedef should be better:
typedef const char* (*attrListPtr) const;
>
First I don't really understand this typedef and then I was wondering
how this should be rewritten using #define

I also have another typedef which I do understand. It is used for
function aliasing. But I was wondering how and if it is possible in
such a case also to replace the typedef by using #define.

For instance how would you rewrite:

typedef double (*Addition)(double value1, double value2);
Don't use #define with this.
And I don't know how to do it.
>
??

Many thanks in advance,

rr
Jun 27 '08 #3

P: n/a
wo*********@yahoo.com wrote:
I need to rewrite some typedef to #define.
Why?

--
Ian Collins.
Jun 27 '08 #4

P: n/a
wo*********@yahoo.com wrote:
I also have another typedef which I do understand. It is used for
function aliasing. But I was wondering how and if it is possible in
such a case also to replace the typedef by using #define.
It's not possible. I can't understand why you would want to.
Jun 27 '08 #5

P: n/a
On 12 avr, 18:36, "wongjoek...@yahoo.com" <wongjoek...@yahoo.com>
wrote:
I need to rewrite some typedef to #define.
To start with, no you don't. If anything, you should be going
in the other direction.
For instance I rewrote
typedef void* handle
to
#define handle void*
Which isn't at all the same thing, consider:

const handle whatever ;
But I saw for instance another typedef in my code which I
don't understand, which is
typedef const char* const* attrListPtr;
First I don't really understand this typedef and then I was
wondering how this should be rewritten using #define
It can't be. In general, nothing involving pointers and arrays
can be.

(Well, strictly speaking:

typedef char const* const* hiddenAttrListPtr ;
#define attrListPtr hiddenAttrListPtr

will work.)
I also have another typedef which I do understand. It is used
for function aliasing. But I was wondering how and if it is
possible in such a case also to replace the typedef by using
#define.
For instance how would you rewrite:
typedef double (*Addition)(double value1, double value2);
??
As above. But as I said, you should be going the other way.
#define doesn't work as a typedef, and creates unnecessary
confusion.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orient閑 objet/
Beratung in objektorientierter Datenverarbeitung
9 place S閙ard, 78210 St.-Cyr-l'蒫ole, France, +33 (0)1 30 23 00 34
Jun 27 '08 #6

P: n/a
On 12 avr, 19:01, "Alf P. Steinbach" <al...@start.nowrote:
* wongjoek...@yahoo.com:
[...]
But I saw for instance another typedef in my code which I don't
understand, which is
typedef const char* const* attrListPtr;
You have written ("my code") something you don't understand.
For many of us, "my code" means some horrible junk that we got
pushed off on us because no one else could understand it:-). I
didn't write it, anymore than I made "my car".

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orient閑 objet/
Beratung in objektorientierter Datenverarbeitung
9 place S閙ard, 78210 St.-Cyr-l'蒫ole, France, +33 (0)1 30 23 00 34
Jun 27 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.