Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What about this line?

Status
Not open for further replies.

Gaudalier

Programmer
Jul 3, 2000
75
MX
Hi there!
I'm coding a function from C to asm.

I need to know how much memory does Allocate the next c line:

//typedef struct { BYTE X,Y,W,H; } offsetPOS;
//offsetPOS *POS_buffer;
nControls=100
POS_buffer=(offsetPOS *)(malloc(nControls))

How many byte is allocated at POS_Buffer? 400?

Can you enligh me a bit from "(offsetPOS *)" ???

Thanks

-----
 
Code:
nControls = 100; // semicolon?
100 (one hundred, or 10*10 in decimals), of course. What's a problem?..
 
I'm traslating this C code to Assembler code:

POS_buffer=(offsetPOS *)(malloc(nControls))

Ok, Malloc parameter = number of contiguous bytes of storage to be allocated, 100 indicated by nControls.

What I dunno is "(offsetPOS *)":

It's mean to be size of offsetPOS (4) times malloc(100)) = 400 contiguous bytes???



-----
 
The way I see it...

1) [tt]offsetPOS[/tt] is a structure.
2) [tt]POS_buffer[/tt] is a pointer to an [tt]offsetPOS[/tt] structure.
3) [tt]nControls[/tt] is a variable (I assume type [tt]size_t[/tt]) that's being set to 100.
4) The [tt]malloc(nControls)[/tt] is allocating some memory 100 bytes long (because [tt]nControls[/tt] = 100), and it returns the address of the memory.
5) The [tt](offsetPOS *)[/tt] is casting that memory address returned by the [tt]malloc[/tt] to the type "pointer to an [tt]offsetPOS[/tt] structure".
6) The variable [tt]POS_buffer[/tt] ends up holding that value.

Hope this helps.
 
Yeah, the asterisk ([tt]*[/tt]) in this case is indicating a "pointer", not multiplication.

Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top