Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

pointer validation in C

Status
Not open for further replies.

kk2mkk

Member level 2
Member level 2
Joined
Apr 20, 2006
Messages
44
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Location
Hyderabad India
Activity points
1,622
if u have given a pointer *ptr how to validate weather this ptr points to a type char,float, double,int etc

i have googeled a lot but i dint got the answer.

thanks
KK
 

typedef.. : ? TRUE:FALSE = ... statement will tell you as a logical echo

typedef ? can have logicaly many qualifiers to many statements ask of it

you hash a define #define you can # an typedefine or typedef

you can also ask a defined entity what it is by echo in logic as per the given logical string asked or defined as any entity setter....

only way i can say it
just to see stuff # hashed
is c... as a #
as a # is a definate

c will also use the same sub qualification statement to parse your logical questions

a hash # is a logical known argument upon case a bit like a logical algurithm in its simplest forms

simply a way to extend the logise of the registers avalible
or like adding layers to a cake

as the base will be the closest to the recipe needed

* just points to a position in memory
so
? typedef->name of entity : ? : TRUE : FALSE

in c building a lookuptable as a typedefined header include and a set of defined entitys you can then look up the entitys as your entrys defined the way in arrays
even 3d arrays can be different lenght this way...
you use a

#define DOUBLES[0] = DOUBLE;
#define DOUBLES[1] = DOUBLE;
...
...

#define DWORDS[0] = DWORD;
...
#define DWORDS[2] = DWORD;
ETC...

THEN...
adding after LIKE...
#typedef DOUBLES[4],DWORDS[3],LONGS[2];

you can also assign sudonames to your types
so in your app you can have an array of types names

with a pointer YOU define what area of memory you look at

the way to do this is to use the sizeof command to size
an area of memory at a pointers address

x= sizeof *ptr;
then compare x to a known size typedef ...
this is laborious ... in terms of code size

it depends where your programming application comes from

judging what variable is stored in memory is hard ...
unless you have a hook on its poker {setters defined size}

a setter is a #define.... as a definate size

so.... there is no way without hooking the exe in memory and instead of loking at the size of the variable
find what referances it and look at what its defined size in memory is then look up the size and give an output

this is also easy if its a known exe or dll you want to hook too {easy}

if its in the same c app you want to see what it is then concider the defined typedefined array method above as a base for your class as an inc header
 

You don't know to what *ptr points and want to know?. I don't understand your question.
 

You could define the ptr* something where something is a struct. A menber of the struct identifies the type. Then you can check it.
 

hey you can just assign a variable to that & then just compile/build the program. then compiler will tell you what was the pointer type & which type you have used it for... simple... isn't it.... :)
 

main()
{
int *ip,i;
float *fp,f;
char *cp,ch;
ip=&i; fp=&f; cp=&ch;

ip++;
fp++;
cp++;

if((int)ip-(int)&i == 2 )
printf("\n ip is integer ptr");

if((int)fp-(int)&f == 4)
printf("\n fp is float ptr");

if((int)cp - (int)&ch == 1)
printf("\ncp is char ptr");
}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top