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

Which preprecessor directive will detect if a typedef exists yet? Eg #if IS_TYPE(sometype_t)?

Thanks.

Oct 29 '08 #1
4 3574
Kevin Smith wrote:
Thanks.
for what? Please include your question in the body of the post.

As for detecting typedefs, I don't think you can though ICBW. The
preprocessor operates in an earlier stage of translation than the point
where typedefes get created.

--
Mark McIntyre

CLC FAQ <http://c-faq.com/>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>
Oct 29 '08 #2
Kevin Smith wrote:
[Re: Which preprecessor directive will detect if a typedef exists yet?
Eg #if IS_TYPE(sometype_t)?]
Thanks.
Please don't rely upon the subject line to convey your question. It's
quite common for people to read the body of a message without even
looking at the subject line. Put the question itself in your post,
though it's OK to put a summary of the question in the subject line.

To answer your question, C provides no mechanism whereby your code can
test for the presence of a typedef. Even if C did provide one, it could
not be available for use in a #if: preprocessor directives are handled
during translation phase 4; typedefs don't get interpreted until
translation phase 7. If any method for doing this were added to C, it
would have to rely upon a phase 7 construct, perhaps
if(is_typedef(sometype_t)).

However, the main thing you would want to do with something like
is_typedef() is to control how the specified identifier is used in your
code. Unfortunately, both branches of the if statement would have to use
that identifier in a fashion that is legal, whether or not it is a
typedef, which defeats the only purpose it could reasonably serve.

It might be possible to get around this problem by splitting translation
phase 7 into 2 or more phases, but I've given the idea just enough
thought to realize that it would be horrendously difficult to do so.
Oct 29 '08 #3
Mark McIntyre writes:
As for detecting typedefs, I don't think you can though ICBW. The
preprocessor operates in an earlier stage of translation than the point
where typedefes get created.
The general ways to do it:

If it's your own type, you can wrap the definition in something like
#ifndef FOOBAR_TYPE_DEFINED
#define FOOBAR_TYPE_DEFINED
typedef ... Foobar;
#endif
or extend that to wrap the entire include-file which defines the
type, in #ifndef FILE_H_ / #define FILE_H_ / #endif

Otherwise #ifdef on something related to the type. E.g. only use
pthread_rwlock_t if PTHREAD_RWLOCK_INITIALIZER is #defined. Until
you port to a machine which defines one but not the other. Then

you switch to #defining HAVE_PTHREAD_RWLOCK_T in Makefile or a
yourapp-config.h file, maybe written by tools like autoconf or
metaconfig.

--
Hallvard
Oct 29 '08 #4
On Oct 29, 10:54 am, Kevin Smith <n...@spam.comwrote:
Thanks.
You're welcome.
Don't put the question in the subject header.
Your question is in the FAQ, 10.15.
<http://c-faq.com/>
Oct 29 '08 #5

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

Similar topics

2
by: Paul | last post by:
I am creating a Program for college, in which the Program will read a Folder and create a HTML page from the pictures that are storrd in that folder. . What would be the best way to do...
6
by: Stephane Belzile | last post by:
Is there a way I can detect in vb.Net the power has switched to a UPS unit in case of power failure? Thanks
0
by: Paul | last post by:
I am creating a Program for college, in which the Program will read a Folder and create a HTML page from the pictures that are storrd in that folder. .. What would be the best way to do it in VB...
7
by: Tony Johansson | last post by:
Hello Experts! I have the following Array template class see below. I execute these three statements statement 1: Array<int> x(5); statement 2: cin >>x; statement 3: Array<int>::element_type ...
2
by: DB | last post by:
Hi All, Just a quick question.................... Which is the most efficient XML parser for reading XML file? I just wanna read the file( I m not goin to write into it). Thanks, Deepak
1
by: Tomas | last post by:
Is there any sequence diagram on the web that clearly shows in which order all Page methods (load, render and so on) are being called compared to the order the page's contained control methods are...
15
by: ezmiller | last post by:
Does anybody know how to use javascript to test whether or not an internet connection exists? Is this possible even?
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...
1
by: CJ | last post by:
Hello friends, It seems to be quite common in libraries (e.g. GMP) to have typedefs like typedef struct { /* stuff */ } __type_struct; typedef __type_struct type_t;
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
1
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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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)...
0
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: 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...

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.