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

typedef and #define

What will happen if i replace a typedef with a #define?
Mar 4 '08 #1
18 1828
vivek wrote:
What will happen if i replace a typedef with a #define?
See:

<http://c-faq.com/decl/typedefvsdefine.html>

Mar 4 '08 #2
vivek wrote:
What will happen if i replace a typedef with a #define?
Your code will break [1].

[1] Probably. Why court disaster? Why replace the right construct with
the wrong one?

--
"Ashes are burning the way." - Renaissance, /Ashes Are Burning/

Hewlett-Packard Limited registered no:
registered office: Cain Road, Bracknell, Berks RG12 1HN 690597 England

Mar 4 '08 #3
On Mar 4, 4:56 am, vivek <gvivek2...@gmail.comwrote:
What will happen if i replace a typedef with a #define?
It depends. Let's suppose you've created a typedef for a pointer to
int:

typedef int *iptr;
iptr px, py;

Both px and py will be typed int*.

Now we replace it with a macro:
#define IPTR int *
IPTR px, py;

After preprocessing, this will expand to
int * px, py;

In this case, only px will be typed int*; py will be a plain int.

So, for this particular case, you get different results.

Some typedefs would be difficult to replace with a macro. For
example, take

typedef int *(*(*foo)[20])(char c);

foo is a synonym for "pointer to 20-element array of pointers to
functions taking a char parameter and returning a pointer to int." A
simple macro to replace this typedef would be, well, not so simple.
Mar 4 '08 #4
On Mar 4, 2:56*am, vivek <gvivek2...@gmail.comwrote:
What will happen if i replace a typedef with a #define?
Nothing of consequence.

Eminent computer scientist Scott Nudds demonstrated, years ago, that
they are the same thing.

:)
Mar 4 '08 #5
On Mar 4, 11:44 am, Kaz Kylheku <kkylh...@gmail.comwrote:
On Mar 4, 2:56 am, vivek <gvivek2...@gmail.comwrote:
What will happen if i replace a typedef with a #define?

Nothing of consequence.

Eminent computer scientist S**** N**** demonstrated, years ago, that
they are the same thing.

:)
DO NOT SPEAK THAT NAME, lest he notice and come back to pester us
again, with the Three Stooges (Twink, McCormack, and Just Richard)
egging him on.
Mar 4 '08 #6

"John Bode" <jo*******@my-deja.comwrote in message
news:81**********************************@v3g2000h sc.googlegroups.com...
On Mar 4, 4:56 am, vivek <gvivek2...@gmail.comwrote:
>What will happen if i replace a typedef with a #define?
Some typedefs would be difficult to replace with a macro. For
example, take

typedef int *(*(*foo)[20])(char c);
>foo is a synonym for "pointer to 20-element array of pointers to
functions taking a char parameter and returning a pointer to int."
Are you saying that:

typedef int *(*(*foo)[20])(char c);

Creates a complex type with an alias of foo; while:

int *(*(*bar)[20])(char c);

Creates a variable bar with that same type? (Not sure what the 'c' is doing
in there).

How would I specify that same complex type without either the foo or bar
tag, as in a cast for example? Is it just:

(int *(*(*)[20])(char c))

?

--
Bart


Mar 4 '08 #7
John Bode wrote:
>
On Mar 4, 11:44 am, Kaz Kylheku <kkylh...@gmail.comwrote:
On Mar 4, 2:56 am, vivek <gvivek2...@gmail.comwrote:
What will happen if i replace a typedef with a #define?
Nothing of consequence.

Eminent computer scientist S**** N**** demonstrated, years ago, that
they are the same thing.

:)

DO NOT SPEAK THAT NAME, lest he notice and come back to pester us
again, with the Three Stooges (Twink, McCormack, and Just Richard)
egging him on.
Heh - might as well invoke all the demons...

What ever happened to that lad who preached that hexadecimal was
the one true number system?

--
Morris Dovey
DeSoto Solar
DeSoto, Iowa USA
http://www.iedu.com/DeSoto
Mar 4 '08 #8
Morris Dovey <mr*****@iedu.comwrites:
John Bode wrote:
>>
On Mar 4, 11:44 am, Kaz Kylheku <kkylh...@gmail.comwrote:
On Mar 4, 2:56 am, vivek <gvivek2...@gmail.comwrote:

What will happen if i replace a typedef with a #define?

Nothing of consequence.

Eminent computer scientist S**** N**** demonstrated, years ago, that
they are the same thing.

:)

DO NOT SPEAK THAT NAME, lest he notice and come back to pester us
again, with the Three Stooges (Twink, McCormack, and Just Richard)
egging him on.

Heh - might as well invoke all the demons...
Ah, so _those_ are what flew out my nose when I forgot to ensure
isalpha()'s argument was representable as an unsigned char.

--
Micah J. Cowan
Programmer, musician, typesetting enthusiast, gamer...
http://micah.cowan.name/
Mar 4 '08 #9
On Mar 4, 2:20 pm, Micah Cowan <mi...@cowan.namewrote:
Morris Dovey <mrdo...@iedu.comwrites:
John Bode wrote:
On Mar 4, 11:44 am, Kaz Kylheku <kkylh...@gmail.comwrote:
On Mar 4, 2:56 am, vivek <gvivek2...@gmail.comwrote:
What will happen if i replace a typedef with a #define?
Nothing of consequence.
Eminent computer scientist S**** N**** demonstrated, years ago, that
they are the same thing.
:)
DO NOT SPEAK THAT NAME, lest he notice and come back to pester us
again, with the Three Stooges (Twink, McCormack, and Just Richard)
egging him on.
Heh - might as well invoke all the demons...

Ah, so _those_ are what flew out my nose when I forgot to ensure
isalpha()'s argument was representable as an unsigned char.
Gesundheit.
Mar 4 '08 #10
vivek wrote:
>
What will happen if i replace a typedef with a #define?
Your program will fail to compile, your girlfriend will leave you,
your hair will fall out, and your father will smell of elderberry
wine.

Or simply consider what happens if you replace:

typedef char *CHAR_PTR;
with
#define CHAR_PTR char *

and your program includes:

CHAR_PTR pt1, pt2;

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>
Mar 4 '08 #11
vivek <gv********@gmail.comwrites:
What will happen if i replace a typedef with a #define?
Regret.

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Mar 5 '08 #12
Morris Dovey <mr*****@iedu.comwrote:
John Bode wrote:

On Mar 4, 11:44 am, Kaz Kylheku <kkylh...@gmail.comwrote:
On Mar 4, 2:56 am, vivek <gvivek2...@gmail.comwrote:
>
What will happen if i replace a typedef with a #define?
>
Nothing of consequence.
>
Eminent computer scientist S**** N**** demonstrated, years ago, that
they are the same thing.
>
:)
DO NOT SPEAK THAT NAME, lest he notice and come back to pester us
again, with the Three Stooges (Twink, McCormack, and Just Richard)
egging him on.

Heh - might as well invoke all the demons...

What ever happened to that lad who preached that hexadecimal was
the one true number system?
I don't know, but have you SEEN the CHAIR recently?

Richard
Mar 5 '08 #13
Richard Bos wrote:
I don't know, but have you SEEN the CHAIR recently?
I'm obviously missing something (either I've been away too long
or didn't get enough sleep last night) - what have I missed?
(e-mail is ok if you prefer).

--
Morris Dovey
DeSoto Solar
DeSoto, Iowa USA
http://www.iedu.com/DeSoto/
Mar 5 '08 #14
Richard Bos wrote:
I don't know, but have you SEEN the CHAIR recently?
I'm obviously missing something (either I've been away too long
or didn't get enough sleep last night) - what have I missed?
(e-mail is ok if you prefer).

--
Morris Dovey
DeSoto Solar
DeSoto, Iowa USA
http://www.iedu.com/DeSoto/
Mar 5 '08 #15
Morris Dovey <mr*****@iedu.comwrote:
Richard Bos wrote:
I don't know, but have you SEEN the CHAIR recently?

I'm obviously missing something (either I've been away too long
or didn't get enough sleep last night) - what have I missed?
(e-mail is ok if you prefer).
Xney Z., our erstwhile local KOOK-IN-ITSELF.

Richard
Mar 5 '08 #16
Morris Dovey said:
Richard Bos wrote:
>I don't know, but have you SEEN the CHAIR recently?

I'm obviously missing something (either I've been away too long
or didn't get enough sleep last night) - what have I missed?
Don't you remember Karl Malbrain? You replied to him at least once...

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Mar 5 '08 #17
Richard Heathfield wrote:
Don't you remember Karl Malbrain? You replied to him at least once...
Ah - thank you. As you probably recall, I don't killfile - but
have slid some few people into the "best forgotten" catagory.

--
Morris Dovey
DeSoto Solar
DeSoto, Iowa USA
http://www.iedu.com/DeSoto
Mar 5 '08 #18

"Richard Heathfield" <rj*@see.sig.invalidwrote in message
news:2_******************************@bt.com...
Morris Dovey said:
>Richard Bos wrote:
>>I don't know, but have you SEEN the CHAIR recently?

I'm obviously missing something (either I've been away too long
or didn't get enough sleep last night) - what have I missed?

Don't you remember Karl Malbrain? You replied to him at least once...
The Chair has been seen near the schlichty toves. I had to terminate my
convo with Karl tonight. Malbrain was shown to an all-you-can-eat english
buffet, aka was either food- or waterboarded.

--
Gerry Ford

"Er hat sich georgiert." Der Spiegel, 2008, sich auf Chimpy Eins komma null
beziehend.
Mar 6 '08 #19

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...
6
by: wongjoekmeu | last post by:
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,...
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
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.