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

whats the meaning of typedef

24
Hi
can somebody tell me what does this line means in the c programming "typedef struct terms* express;"?

thank
Oct 6 '06 #1
6 4168
tyreld
144 100+
The typedef keyword is used to introduce synonyms for types which are intrinsic types (int, float, etc.) or where declared some other way (structs, classes). The new name becomes equivalent to the type you wanted.

Expand|Select|Wrap|Line Numbers
  1.  
  2. struct terms {
  3.   // some fields
  4. };
  5.  
  6. // Declare a pointer of struct terms.
  7. struct terms *termptr;
  8.  
Now we accomplish the same thing using a typedef.

Expand|Select|Wrap|Line Numbers
  1.  
  2. struct terms {
  3.   // some fields
  4. };
  5.  
  6. typedef struct terms *express;
  7.  
  8. // The decleration of "termptr" is equivalent to our previous example
  9. express termptr;
  10.  
I generally think it is a poor idea to introduce a new type name for pointer types that don't explicitly indicate in the type name that it is a pointer type. In the last example I think it would be better to have named the new type "p_express", or "express_ptr", or "terms_ptr", or "p_terms."
Oct 6 '06 #2
cool17
24
okok thx

but will it be the same as in this case the '*' is in front of the term and not the express

typedef struct terms* express;


so will it make any different?
Oct 6 '06 #3
cool17
24
The code is as follow, thanks again

#ifndef _EXPRESSION_H
#define _EXPRESSION_H


typedef struct terms* express;

typedef struct expressions* myexp;

struct expressions
{
express* exp;
int numberOfTerms;
};

struct terms
{

double x_value;
double x_power;
double x_times;
int positive;
int isX;
int KnowX;

};



myexp createExpression();

void string2Expression(char*,myexp*);

char* expression2String(myexp);


#endif
Oct 6 '06 #4
m013690
23
no, the whitespace does not matter with regard to the pointer declaration.

terms *express
is the same as
terms* express
Oct 6 '06 #5
tyreld
144 100+
okok thx

but will it be the same as in this case the '*' is in front of the term and not the express

typedef struct terms* express;


so will it make any different?
No, there will be no difference.

Expand|Select|Wrap|Line Numbers
  1. typedef struct terms *express;
  2.  
is the same as

Expand|Select|Wrap|Line Numbers
  1. typedef struct terms* express;
  2.  
is the same as

Expand|Select|Wrap|Line Numbers
  1. typedef struct terms * express;
  2.  
It is mostly a matter of personal preference to a certain extent. However, the first example is how most programmers and documentation will write the declaration.
Oct 6 '06 #6
cool17
24
thank guys...
Oct 6 '06 #7

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

Similar topics

2
by: Immo Birnbaum | last post by:
Hi, I'm trying to solve a programming lab assignment for my college C programming course, but as they taught us two semesters of Java before teaching us any C, I'm having problems with all the...
8
by: Ronny Mandal | last post by:
Consider these two: Typedef struct { int foo, bar } FooBar; struct FooBar { int foo, bar }; What woul be the only difference here; just that I can create new instances by 'Foobar fb, *pfb',...
12
by: aaragon | last post by:
Hello all. I have a simple question that seems trivial but I can't make it to work. I have a class that takes as a template argument, another class. The idea is as follows: #include...
3
by: sam | last post by:
HI, The code is as follows:- #include <stdio.h> 1 2 void * work(void * ptr) 3 { 4 int i; 5 for (i = 0; i < 10; i++) 6 {
8
by: Mohammad Omer Nasir | last post by:
Hi, i made a structure in header file "commonstructs.h" is: typedef struct A { int i; A( ) {
8
by: 2b|!2b==? | last post by:
typedef struct llist_entry_s llist_entry; /* opaque type */ struct llist_entry_s { llist_entry * next; char * keyword; char * value; llist_entry() :next(0), keyword(0), value(0) {
5
by: nas | last post by:
Hi..Please tell me what is the meaning of these lines static IFastString *(*pfnlr)(const char *)=0 and IFastString *(**ppfn)(const char *)=pfnlr Where IFastString is the abstract class
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...
7
by: Alex | last post by:
The code below can't be compiled: typedef char* POINTER; const POINTER ptr; ptr++; The compiler (Sun C 5.8 Patch 121015-04 2007/01/10) complains: "test.c", line ...: operand must be...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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.