473,670 Members | 2,569 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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)(dou ble value1, double value2);

??

Many thanks in advance,

rr
Jun 27 '08 #1
6 2152
* wo*********@yah oo.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)(dou ble value1, double value2);
One wouldn't.
Cheers, & hth.,

- Alf
Jun 27 '08 #2
On 4ÔÂ13ÈÕ, ÉÏÎç12ʱ36·Ö, "wongjoek...@ya hoo.com" <wongjoek...@ya hoo.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)(dou ble 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*********@yah oo.com wrote:
I need to rewrite some typedef to #define.
Why?

--
Ian Collins.
Jun 27 '08 #4
wo*********@yah oo.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...@ya hoo.com" <wongjoek...@ya hoo.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* hiddenAttrListP tr ;
#define attrListPtr hiddenAttrListP tr

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)(dou ble 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 objektorientier ter Datenverarbeitu ng
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.no wrote:
* wongjoek...@yah oo.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 objektorientier ter Datenverarbeitu ng
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
1370
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 typedefs. This, mainly because occasionally a user forgets that these are pointer "types", and declares one or more variable on the same line, leading to errors. E.g. right now I have this, which works fine, with the caveat that only a single...
15
5653
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 everything in a /*...*/ comment and appending the 'hail world' code. Is there an easier, and, let's say, more
10
12207
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 pseudo-code: #if typedef(int64_t) typedef int64_t MY_BIG_INT #elif typedef(long long) typedef long long MY_BIG_INT #else
10
7500
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 are different ?
134
9022
by: jacob navia | last post by:
Hi Suppose you have somewhere #define BOOL int and somewhere else typedef BOOL int;
12
8228
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 the preprocessor to detect that ui32 already exists, when preprocessing F.c? The idea is that F.c will typedef ui32 as above if and only if such typedef is not already in some include file used by F.c.
3
9798
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 function model? And can use the second declaration to define a function pointer as follow:
15
5087
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 are there any reasons that we should prefer one over the other and how is typedef internally implemented?
1
5218
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 think about typedef as being a complete encapsulated type - you can't add to it after you have declared it.
0
8466
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8384
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8590
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8659
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7410
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6211
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4387
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2035
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1790
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.