rewriting typedef to define

W

wongjoekmeu

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
 
K

kepeng

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

Juha Nieminen

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

James Kanze

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

James Kanze

* (e-mail address removed):

[...]
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".
 

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,954
Messages
2,570,116
Members
46,704
Latest member
BernadineF

Latest Threads

Top