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

About typedef

Can anyone tell me the use of typedef in C
What will this statement do:

typedef unsigned char byte;

plz help me......
Oct 7 '07 #1
3 1207
JosAH
11,448 Expert 8TB
Can anyone tell me the use of typedef in C
What will this statement do:

typedef unsigned char byte;

plz help me......
Think of an ordinary variable definition; e.g.

Expand|Select|Wrap|Line Numbers
  1. int i;
  2. char* p;
  3.  
This defines two variables 'i' and 'p'. Now prepend them with the 'typedef' keyword:

Expand|Select|Wrap|Line Numbers
  1. typedef int i;
  2. typedef char* p;
  3.  
Now you have to aliases 'i' and 'p' for the typed 'int' and 'char*' so you may now
use them as:

Expand|Select|Wrap|Line Numbers
  1. i ii; // an int
  2. p pp; // a char*
  3.  
kind regards,

Jos
Oct 7 '07 #2
Thanks a lot for your answer...One more doubt How are the datatypes char and unsigned char different
Oct 7 '07 #3
JosAH
11,448 Expert 8TB
Thanks a lot for your answer...One more doubt How are the datatypes char and unsigned char different
I already answered that question in your other thread.

kind regards,

Jos
Oct 7 '07 #4

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

Similar topics

36
by: Bhalchandra Thatte | last post by:
I am allocating a block of memory using malloc. I want to use it to store a "header" structure followed by structs in my application. How to calculate the alignment without making any assumption...
7
by: Rano | last post by:
/* Hello, I've got some troubles with a stupid program... In fact, I just start with the C language and sometime I don't understand how I really have to use malloc. I've readden the FAQ...
20
by: ma0001yu | last post by:
Hi, all. I feel confuse about below struct definition: typedef struct TAG { comments.... }; What my confusion is: is typedef extra??why we not just use
12
by: spibou | last post by:
I have two identical files , u1.c and u2.c which only contain the line typedef int Q ; When I issue "splint u1.c u2.c" I get u2.c:1:13: Datatype Q defined more than once A function or variable...
4
by: vcinquini | last post by:
I've always learned about typedef as a statement that creates an alias for a type. For example: typedef long DWORD; but I'm confused about the following typedef. Which is the type and which...
33
by: jobo | last post by:
If I have the function: int f(int (*h)(int)) { return (*h)(13); } What exactly does (int (*h)(int)) do? So it's taking a pointer but what's with the two ints? Thanks.
75
by: Steven T. Hatton | last post by:
No, this is not a troll, and I am not promoting Java, C-flat, D, APL, Bash, Mathematica, SML, or LISP. A college teacher recently posted to this newsgroup regarding her observation that there has...
3
by: goodmen | last post by:
I think the boost::concept_check is too complex. Here is my solution about static interface and concept. The static interface can be used as function param. It is just a proxy of the real...
7
by: ot_007_2001 | last post by:
Hi, all, For pricticing defination of structure in C, I wrote a small code as follow: #include<stdio.h> struct datastruct { int data;
21
by: heavyz | last post by:
In C, if i want to declare a struct, there are 3 methods to do so: 1: struct dummy { ... }; 2: typedef struct { ... } dummy; 3: typedef struct _dummy { ... } dummy; Usually i use the first...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
0
tracyyun
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...
0
agi2029
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,...

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.