473,406 Members | 2,273 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,406 software developers and data experts.

rewriting typedef to define

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
6 2125
* 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
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
wo*********@yahoo.com wrote:
I need to rewrite some typedef to #define.
Why?

--
Ian Collins.
Jun 27 '08 #4
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
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ée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jun 27 '08 #6
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ée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jun 27 '08 #7

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

Similar topics

5
by: aekalman | last post by:
Hi all. I'm revising part of a large body of code that runs on a variety of very different targets, and one of the things I'd like to do is move away from certain "#define'd types" in favor of...
15
by: Merrill & Michele | last post by:
typedef struct { WORD versionNumber; WORD offset; } MENUITEMTEMPLATEHEADER; This is from vol 5 of unnamed platform's programmer's reference. I could make this conforming by enclosing...
10
by: Kenneth Brody | last post by:
Is there any way to know if there is a typedef of a given name? Specifically, I need to know if the compiler has a 64-bit integer type, and need to know if "int64_t" exists. Something like this...
10
by: O Plameras | last post by:
Are there differences in terms of functionality of, #define and typedef ? By the above I mean any instance when the outcome obtained by running two versions (1) and (2) below of C codes...
134
by: jacob navia | last post by:
Hi Suppose you have somewhere #define BOOL int and somewhere else typedef BOOL int;
12
by: Thomas Carter | last post by:
Imagine that there is some include file f.h that contains the following line: typedef unsigned int ui32 ; My question is: If I have a C source file F.c that includes f.h, is it possible for...
3
by: robin liu | last post by:
What's the difference between these two declarations ? 1) typedef void (*pf)(void); 2) typedef void f(void); the first declaration is define a function pointer, what is the second ? define a...
15
by: sam_cit | last post by:
I noticed that what is being done by typedef can very much be done by macro, and i also think there must be a specific reason as to why typedef was introduced, what is the exact difference, and...
1
by: sophia | last post by:
Dear all, the following are the differences b/w #define and typedef ,which i have seen in Peter van der lindens book. is there any other difference between thes two ? The right way to...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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
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...
0
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,...
0
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...

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.