Hi,
I have an intersting quesiton in my view. I have two write a
macro which tell what is the
type of argument being passed to it
i.e int, short, long, signed , unsigned..etc
like
typedef T unsigned int
value(T)
I have to printf() what kind of value T is...
Regards
Gurminder 11 1670
sunny said:
Hi,
I have an intersting quesiton in my view.
An interesting question? Cool.
I have two write a macro which tell what is the
type of argument being passed to it i.e int, short,
long, signed , unsigned..etc like
typedef T unsigned int
value(T)
I have to printf() what kind of value T is...
Okay, understood. Now, you said you had an interesting question, but I don't
see a question.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999 http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
sunny wrote:
Hi,
I have an intersting quesiton in my view. I have two write a
macro which tell what is the
type of argument being passed to it
i.e int, short, long, signed , unsigned..etc
like
typedef T unsigned int
value(T)
I have to printf() what kind of value T is...
That's a bit of a challenge. Straight C doesnt have any type-inquiry
function at either compile-time or run-time, so just knowing the type
isnt of much help.
There is the rather barren sizeof() function, which will tell you how
many bytes T occupies, but that isnt very helpful, unless you assume
only integer-like types are going to be passed in. Even then it's
going to be a bit tricky to figure out if T is signed or unsigned.
Perhaps you could retell your question, in a bit more detail.
sunny (in 11************* *********@75g20 00...legro ups.com) said:
| Hi,
| I have an intersting quesiton in my view. I have two
| write a macro which tell what is the
| type of argument being passed to it
| i.e int, short, long, signed , unsigned..etc
| like
|
| typedef T unsigned int
| value(T)
|
| I have to printf() what kind of value T is...
An interesting assignment indeed. When is your solution due?
--
Morris Dovey
DeSoto Solar
DeSoto, Iowa USA http://www.iedu.com/DeSoto
On Wed, 12 Jul 2006, sunny wrote:
Hi,
I have an intersting quesiton in my view. I have two write a
macro which tell what is the
type of argument being passed to it
i.e int, short, long, signed , unsigned..etc
like
typedef T unsigned int
value(T)
I have to printf() what kind of value T is...
Regards
Gurminder
If you want to do reflection in C you would need *much more*
than just a simple macro. At the very least, you would need to
create a struct wrapper containing a type field (enum) and a data
field (union of all data types used in your program). You would
then have to wrap all your "reflective " data with this struct.
Tak-Shing
sunny wrote:
Hi,
I have an intersting quesiton in my view. I have two write a
macro which tell what is the
type of argument being passed to it
i.e int, short, long, signed , unsigned..etc
like
typedef T unsigned int
value(T)
I have to printf() what kind of value T is...
I can think of a way to distinguish between signed and unsigned
but distinguishing between int and long I have no idea. I'll go
out on a limp and say that it can't be done.
Tak-Shing Chan wrote:
If you want to do reflection in C you would need *much more*
than just a simple macro. At the very least, you would need to
create a struct wrapper containing a type field (enum) and a data
field (union of all data types used in your program). You would
then have to wrap all your "reflective " data with this struct.
I have no idea what reflection means in this context. sp****@gmail.co m wrote:
Tak-Shing Chan wrote:
> If you want to do reflection in C you would need *much more* than just a simple macro. At the very least, you would need to create a struct wrapper containing a type field (enum) and a data field (union of all data types used in your program). You would then have to wrap all your "reflective " data with this struct.
I have no idea what reflection means in this context.
Typical in OO languages is reflection:
"More generally, reflection is an activity in computation that allows an
object to have information about the structure and reason about its own
computation. The programming paradigm driven by reflection is called
reflective programming."
<http://en.wikipedia.or g/wiki/Reflection_%28c omputer_science %29>
Compare with introspection: The capability of some languages to
determine the type of objects at runtime.
<http://en.wikipedia.or g/wiki/Introspection_% 28computer_scie nce%29>
People are simulating reflection in C:
<http://www.google.com/search?hl=en&lr =&q=%22reflecti on+in+C%22>
In article <11************ *********@b28g2 000cwb.googlegr oups.com>,
<sp****@gmail.c omwrote:
>sunny wrote:
>I have to printf() what kind of value T is...
>I can think of a way to distinguish between signed and unsigned but distinguishing between int and long I have no idea. I'll go out on a limp and say that it can't be done.
if ( (unsigned T) ULONG_MAX == ULONG_MAX ) ...
Of course if int and long have the same range then it becomes
quite difficult to tell them apart ;-)
--
"It is important to remember that when it comes to law, computers
never make copies, only human beings make copies. Computers are given
commands, not permission. Only people can be given permission."
-- Brad Templeton ro******@ibd.nr c-cnrc.gc.ca (Walter Roberson) writes:
In article <11************ *********@b28g2 000cwb.googlegr oups.com>,
<sp****@gmail.c omwrote:
>>sunny wrote:
>>I have to printf() what kind of value T is...
>>I can think of a way to distinguish between signed and unsigned but distinguishing between int and long I have no idea. I'll go out on a limp and say that it can't be done.
if ( (unsigned T) ULONG_MAX == ULONG_MAX ) ...
Of course if int and long have the same range then it becomes
quite difficult to tell them apart ;-)
You can tell them apart at the cost of a compilation failure. int and
long are compatible for most purposes, but int* and long* are not. If
you have a typedef T that could be either int or long, then of these
two expressions:
(T*)0 == (int*)0
(T*)0 == (long*)0
one will compile and one will not (more precisely one is a constraint
violation requiring a diagnostic).
This could be useful for some kind of pre-compilation configuration
system, but I can't think of any way to use it within a single legal
program.
--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Ancient_Hacker schrieb:
<snip>
There is the rather barren sizeof() function, which will tell you how
sizeof is an operator.
Example of use without parens:
....
p = malloc(number * sizeof *p);
....
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Andrew Dalke |
last post by:
Here's a proposed Q&A for the FAQ based on a couple recent
threads. Appropriate comments appreciated
X.Y: Why doesn't Python have macros like in Lisp or Scheme?
Before answering that, a clarification on what 'macro' means.
A Lisp macro is a way of modifying code when that code is first
defined. It can rearrange the structure of the code, and add and
remove parts of it. Unlike C's #define macro language, Lisp
macros understand the...
|
by: mike420 |
last post by:
I think everyone who used Python will agree that its syntax is
the best thing going for it. It is very readable and easy
for everyone to learn. But, Python does not a have very good
macro capabilities, unfortunately. I'd like to know if it may
be possible to add a powerful macro system to Python, while
keeping its amazing syntax, and if it could be possible to
add Pythonistic syntax to Lisp or Scheme, while keeping all
of the...
|
by: Pete |
last post by:
In Access 95/97 I used to be able to create pull down menus (File,Edit
...) from a macro. It seems there used to be some wizard for that.
However in Access 2000 it seems you have to build your menus by
customizing a toolbar. With this method you have to create a separate
macro for every single menu and sub menu. The old method would allow
me to include several menus (File/ print/ page setup ...) all within
one macro. Now it seems I...
|
by: Newbie_sw2003 |
last post by:
Where should I use them?
I am giving you my understandings. Please correct me if I am wrong:
MACRO:
e.g.:#define ref-name 99
The code is substituted by the MACRO ref-name. So no overhead.
Execution is faster. Where will it be stotred?(Is it in bss/stack/?)
FUNCTION:
|
by: Alexander Ulyanov |
last post by:
Hi all.
Is it possible to pass the whole blocks of code (possibly including
" and ,) as macro parameters?
I want to do something like:
MACRO(FOO, "Foo",
"return "Foobar";",
"foo(); bar();")
| |
by: lasek |
last post by:
Hi...in some posts i've read...something about using macro rather then
function...but difference ??.
Best regards....
|
by: Laurent Deniau |
last post by:
I was playing a bit with the preprocessor of gcc (4.1.1). The following
macros expand to:
#define A(...) __VA_ARGS__
#define B(x,...) __VA_ARGS__
A() -nothing, *no warning*
A(x) -x
B() -nothing, *warning ISO C99 requires rest arguments to be used*
|
by: Takeadoe |
last post by:
Dear NG,
Can someone assist me with writing the little code that is needed to
run an update table query each time the database is opened? From what
I've been able to glean from this group, the Autoexec Macro looks like
the way to go. Could someone please assist?
Thank you very much!
Mike
|
by: Bill |
last post by:
This database has no forms. I am viewing an Access table in datasheet
view. I'd like to execute a macro to execute a function (using
"runcode"). In the function, I'll reading data from the record the
cursor was on in the datasheet at the time I executed the macro.
So, the questions are: 1) In the macro, how to I get my hands on the
record key or record data of the record the cursor was on in the
datasheet at the time I executed the...
|
by: =?Utf-8?B?TGV0emRvXzF0?= |
last post by:
I'd like to create a Macro that will sort some raw data, apprx 20k lines,
remove some lines based upon a condition in a certain column. Then copy this
data into a new spreadsheet and sort the data again and delete the unwanted
data and repeat few more times in new sheets. End product will be
apprximately 7 or 8 sheets - 1 for Active Customers, Inactive Customers,
Pending Installs, Etc...
I'm getting hung up I believe with naming...
|
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: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
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...
| |