Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > typedef v macro

Reply
Thread Tools

typedef v macro

 
 
Uno
Guest
Posts: n/a
 
      12-01-2010
Hello ng,

I hope this message finds you all well. It's been a while since I've
had any real time to devote to programming and usenet, and while I'll
hope to stay busy as a handyman through the winter, I'll take it as the
silver lining that I can pursue avocation and hobby otherwise.

Keith posted this source in comp.std.c:

$ gcc -Wall -Wextra e2.c -o out
$ ./out
float_t is not a macro
$ cat e2.c
#include <math.h>
#include <stdio.h>
int main(void)
{
#ifdef float_t
puts("float_t is a macro");
#else
puts("float_t is not a macro");
#endif
return 0;
}
// gcc -Wall -Wextra e2.c -o out
$

1) I'm looking for general comments on the above. including whether you
get different output.

2) Can a conforming implementation render the other possibility?

Thanks for your comment,
and cheers,
--
Uno
 
Reply With Quote
 
 
 
 
Keith Thompson
Guest
Posts: n/a
 
      12-01-2010
Uno <(E-Mail Removed)> writes:
> I hope this message finds you all well. It's been a while since I've
> had any real time to devote to programming and usenet, and while I'll
> hope to stay busy as a handyman through the winter, I'll take it as the
> silver lining that I can pursue avocation and hobby otherwise.
>
> Keith posted this source in comp.std.c:
>
> $ gcc -Wall -Wextra e2.c -o out
> $ ./out
> float_t is not a macro
> $ cat e2.c
> #include <math.h>
> #include <stdio.h>
> int main(void)
> {
> #ifdef float_t
> puts("float_t is a macro");
> #else
> puts("float_t is not a macro");
> #endif
> return 0;
> }
> // gcc -Wall -Wextra e2.c -o out
> $
>
> 1) I'm looking for general comments on the above. including whether you
> get different output.
>
> 2) Can a conforming implementation render the other possibility?


If you wanted to discuss this, surely it would have made more
sense to post a followup in comp.std.c rather than starting a new
thread here in comp.lang.c. You could at least have refered to,
or even quoted, the argument I made there that float_t *cannot*
be a macro in a conforming implementation.

I believe the following program is strictly conforming:

#include <math.h>
int main(void) {
int float_t;
return 0;
}

If float_t were a macro usable as a type name, it would fail
to compile.

I do think the Standard would be slighly clearer if it stated
explicitly that the types defined in the various standard headers
are typedefs.

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
 
 
 
Uno
Guest
Posts: n/a
 
      12-03-2010
Keith Thompson wrote:
> Uno <(E-Mail Removed)> writes:
>> I hope this message finds you all well. It's been a while since I've
>> had any real time to devote to programming and usenet, and while I'll
>> hope to stay busy as a handyman through the winter, I'll take it as the
>> silver lining that I can pursue avocation and hobby otherwise.
>>
>> Keith posted this source in comp.std.c:
>>
>> $ gcc -Wall -Wextra e2.c -o out
>> $ ./out
>> float_t is not a macro
>> $ cat e2.c
>> #include <math.h>
>> #include <stdio.h>
>> int main(void)
>> {
>> #ifdef float_t
>> puts("float_t is a macro");
>> #else
>> puts("float_t is not a macro");
>> #endif
>> return 0;
>> }
>> // gcc -Wall -Wextra e2.c -o out
>> $
>>
>> 1) I'm looking for general comments on the above. including whether you
>> get different output.
>>
>> 2) Can a conforming implementation render the other possibility?

>
> If you wanted to discuss this, surely it would have made more
> sense to post a followup in comp.std.c rather than starting a new
> thread here in comp.lang.c. You could at least have refered to,
> or even quoted, the argument I made there that float_t *cannot*
> be a macro in a conforming implementation.


No, I made the right decision to start a new thread, for a variety of
reasons, and since humor and honoring the recently-departed is always on
topic in clc, my name's not Shirley.

I thought the previous thread very successful in solving many of the
problems with floating point, if only because, when exposed to a larger
audience, they didn't seem to be problems so much as challenges.

Also, crossposted stuff needs to have an expiration date, or heterodoxy
devolves into a flamy thing. I hardly remember all of the context by
now, but I knew that next time I got on usenet, I wanted to feed your
source to gcc and pick up there.
>
> I believe the following program is strictly conforming:
>
> #include <math.h>
> int main(void) {
> int float_t;
> return 0;
> }
>
> If float_t were a macro usable as a type name, it would fail
> to compile.


Ok. No one seems to object. Can one imitate a typedef with a macro as
a useful, non-standard hack?
>
> I do think the Standard would be slighly clearer if it stated
> explicitly that the types defined in the various standard headers
> are typedefs.
>


Can you give other examples here?
--
Uno
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      12-05-2010
Uno <(E-Mail Removed)> writes:
> Keith Thompson wrote:
>> Uno <(E-Mail Removed)> writes:
>>> I hope this message finds you all well. It's been a while since I've
>>> had any real time to devote to programming and usenet, and while I'll
>>> hope to stay busy as a handyman through the winter, I'll take it as the
>>> silver lining that I can pursue avocation and hobby otherwise.
>>>
>>> Keith posted this source in comp.std.c:

[snip]
>> If you wanted to discuss this, surely it would have made more
>> sense to post a followup in comp.std.c rather than starting a new
>> thread here in comp.lang.c. You could at least have refered to,
>> or even quoted, the argument I made there that float_t *cannot*
>> be a macro in a conforming implementation.

>
> No, I made the right decision to start a new thread, for a variety of
> reasons, and since humor and honoring the recently-departed is always on
> topic in clc, my name's not Shirley.


Yes, Mr. Nielsen will indeed be missed.

As for starting a new thread being "the right decision", I'm at a
loss to follow your reasoning. And again, you snipped the part of
the article you quoted in which I answered the very question you
were asking.

[...]
>> I do think the Standard would be slighly clearer if it stated
>> explicitly that the types defined in the various standard headers
>> are typedefs.
>>

>
> Can you give other examples here?


Probably.

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
typedef v/s macro Tagore C Programming 1 12-24-2008 10:53 PM
CRTP-problem: How can the base class typedef a derived class' typedef? oor C++ 0 05-20-2008 12:39 PM
Regarding typedef and macro sam_cit@yahoo.co.in C Programming 15 12-15-2006 07:40 PM
#define macro to enclose an older macro with strings Dead RAM C++ 20 07-14-2004 10:58 AM
macro name from macro? D Senthil Kumar C Programming 1 09-21-2003 07:02 PM



Advertisments