473,396 Members | 1,892 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,396 software developers and data experts.

Simple typedef question......

Hey,

is it possible to typecast inside typedef, for example:

typedef char DEF

but instead of displaying definition as a character and NOT having to typecast later on (aka DEF something = 5; cout << (int)something;)

is there any way to typecast right at the beggining at the typedef stage....

thanks,

P.S any clever alternatives to this welcome..... as long as it has the same result....
Aug 2 '07 #1
5 1718
gpraghuram
1,275 Expert 1GB
Hey,

is it possible to typecast inside typedef, for example:

typedef char DEF

but instead of displaying definition as a character and NOT having to typecast later on (aka DEF something = 5; cout << (int)something;)

is there any way to typecast right at the beggining at the typedef stage....

thanks,

P.S any clever alternatives to this welcome..... as long as it has the same result....
Hi,
Can u explain it more with a example.
I am not ver clear with ur requirement.

Raghuram
Aug 2 '07 #2
um alright well...

typedef unsigned char byte;

but of cource when i define a variable with byte it gives me characters rather than numbers for example:

------------------------------------------------------------
#include <iostream>
typedef unsigned char byte;
using std::cout;

main()
{
byte Value = 5;
cout << Value;
}
------------------------------------------------------------
BUT unless i do cout << (int)Value; i get Value's character equivelent which is a clubs icon....

so instead of type casting a bunch of times is there a way to typecase inside the typedef .... something like

typedef unsigned char (int)byte;

but this wouldent work of cource... so i was wondering if there is some way of making it work......
Aug 2 '07 #3
gpraghuram
1,275 Expert 1GB
um alright well...

typedef unsigned char byte;

but of cource when i define a variable with byte it gives me characters rather than numbers for example:

------------------------------------------------------------
#include <iostream>
typedef unsigned char byte;
using std::cout;

main()
{
byte Value = 5;
cout << Value;
}
------------------------------------------------------------
BUT unless i do cout << (int)Value; i get Value's character equivelent which is a clubs icon....

so instead of type casting a bunch of times is there a way to typecase inside the typedef .... something like

typedef unsigned char (int)byte;

but this wouldent work of cource... so i was wondering if there is some way of making it work......
Hi,
According to my knowledge its not feasible.

Raghuram
Aug 2 '07 #4
alright thanks, ive been actually thinking about it and yeah i kinda agree.... no point since cout will only use it....
Aug 2 '07 #5
weaknessforcats
9,208 Expert Mod 8TB
A coule of things.

but of cource when i define a variable with byte it gives me characters rather than numbers for
This is not true. When you typedef an unsigned char you still have an unsigned char. Next, there are three kinds of built-in variables in C/C++. There are integers, floating point and pointer variables.

An unsigned char is not a pointer or a floating point variable. So, it has to be an integer. In fact, it's just an 8-bit integer that contains integer values.

Then when you cout << achar you should see the integer value. However, the << operator with a char on the right assumes you want the ASCII glyph rather than the number. So yo get A instead of 65.

There are many << operators. The one with an int on the right assumes you want the integer value so you see 65 and not A.

All you have to do is assign your char to an int to see the numeric value.

You do not typecast.

In fact, you never typecast in C++ unless a) you a calling a relic C function, b) you are doing very low level file I/O or c) your design is faulty.
Aug 2 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Alex | last post by:
Hello people, I am getting errors from VS2003 when working with typedef'ed types. For example, assume that I have a type T, defined in a 3rd party include file based on some condition #if...
4
by: Jeffrey Spoon | last post by:
Hello, I am trying to make a simple function that returns a pointer to another function. In my header file I've declared my function pointer: void (*pStateFunction) (void); //assume the function...
176
by: nw | last post by:
Hi, I previously asked for suggestions on teaching testing in C++. Based on some of the replies I received I decided that best way to proceed would be to teach the students how they might write...
11
by: aaragon | last post by:
Hi everyone, I'm trying to create two simple template classes where one of them depends on the other to initialize its member integer variable. After some time, I decided to post a message here...
0
by: mosfet | last post by:
Hi, I have a question regarding derived class, let' say I have a base class class PimItem // A MS COM interface : for people who don't know com it's an interface struct IDispatch { ... };
12
by: Googy | last post by:
Hi!! Can any one explain me the meaning of following notations clearly : 1. typedef char(*(*frpapfrc()))(); frpapfrc f; 2. typedef int (*(arr2d_ptr)()); arr2d_ptr p; 3. typedef int...
2
by: liorjj | last post by:
Hi, I'm new in this area so just a very simple question, I have declared typedef in the header file says (header.h), and some functions in this header as well; My problem is that when i...
3
by: stdlib99 | last post by:
Hi, I have a simple question regarding templates and meta programming. I am going to try and work my way through the C++ Template Metaprogramming, a book by David Abrahams and Aleksey...
16
by: mdh | last post by:
A quick ? :-) question about Typedefs. There is a very brief discussion about this in K&R ( p146). Googling this group, there is a surprising dearth of questions about these. From one of the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
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,...
0
jinu1996
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...

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.