What will happen if i replace a typedef with a #define? 18 1846
vivek wrote:
What will happen if i replace a typedef with a #define?
See:
<http://c-faq.com/decl/typedefvsdefine .html>
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
On Mar 4, 4:56 am, vivek <gvivek2...@gma il.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.
On Mar 4, 2:56*am, vivek <gvivek2...@gma il.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.
:)
On Mar 4, 11:44 am, Kaz Kylheku <kkylh...@gmail .comwrote:
On Mar 4, 2:56 am, vivek <gvivek2...@gma il.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.
"John Bode" <jo*******@my-deja.comwrote in message
news:81******** *************** ***********@v3g 2000hsc.googleg roups.com...
On Mar 4, 4:56 am, vivek <gvivek2...@gma il.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
John Bode wrote:
>
On Mar 4, 11:44 am, Kaz Kylheku <kkylh...@gmail .comwrote:
On Mar 4, 2:56 am, vivek <gvivek2...@gma il.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
Morris Dovey <mr*****@iedu.c omwrites:
John Bode wrote:
>> On Mar 4, 11:44 am, Kaz Kylheku <kkylh...@gmail .comwrote:
On Mar 4, 2:56 am, vivek <gvivek2...@gma il.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/
On Mar 4, 2:20 pm, Micah Cowan <mi...@cowan.na mewrote:
Morris Dovey <mrdo...@iedu.c omwrites:
John Bode wrote:
On Mar 4, 11:44 am, Kaz Kylheku <kkylh...@gmail .comwrote:
On Mar 4, 2:56 am, vivek <gvivek2...@gma il.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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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
|
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
|
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 ?
|
by: jacob navia |
last post by:
Hi
Suppose you have somewhere
#define BOOL int
and somewhere else
typedef BOOL int;
| |
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.
|
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:
|
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?
|
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, which is
|
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.
|
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,...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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,...
|
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...
|
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...
|
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...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |