/ Forside / Teknologi / Udvikling / C/C++ / Nyhedsindlæg
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
C/C++
#NavnPoint
BertelBra.. 2425
pmbruun 695
Master_of.. 501
jdjespers.. 500
kyllekylle 500
Bech_bb 500
scootergr.. 300
gibson 300
molokyle 287
10  strarup 270
What does this line mean....
Fra : holst


Dato : 08-05-01 11:10

md = (struct mailbox_data *)malloc(sizeof(struct mailbox_data),KERNEL);

Problem understanding the malloc() funktion. Can it really take two
parametres?? And what about the pointer - what does it point to??

thanks
Allan, newbie in c-programming




 
 
Bertel Lund Hansen (08-05-2001)
Kommentar
Fra : Bertel Lund Hansen


Dato : 08-05-01 11:53

holst skrev:

>md = (struct mailbox_data *)malloc(sizeof(struct mailbox_data),KERNEL);

>Problem understanding the malloc() funktion. Can it really take two
>parametres?

Not in ANSI-C. It might be a local function written inside the
code.

>And what about the pointer - what does it point to?

When using malloc (the standard C-function), a chunk of memory is
reserved and the pointer, here md, will point to the (first byte
of the) chunk.

The parenthesis, (struct mailbox_data *), is a typecast that
makes sure that md is not just any pointer but a pointer to a
specific type. That will be important later in the program.

--
Bertel
http://lundhansen.dk/bertel/   FIDUSO: http://fiduso.dk/

holst (08-05-2001)
Kommentar
Fra : holst


Dato : 08-05-01 12:13

Thanks..

"Bertel Lund Hansen" <nospamto@lundhansen.dk> wrote in message
news:tojfftg23ra2e1vphb64blpd8esmenugk1@sunsite.auc.dk...
> holst skrev:
>
> >md = (struct mailbox_data *)malloc(sizeof(struct mailbox_data),KERNEL);
>
> >Problem understanding the malloc() funktion. Can it really take two
> >parametres?
>
> Not in ANSI-C. It might be a local function written inside the
> code.
>
> >And what about the pointer - what does it point to?
>
> When using malloc (the standard C-function), a chunk of memory is
> reserved and the pointer, here md, will point to the (first byte
> of the) chunk.
>
> The parenthesis, (struct mailbox_data *), is a typecast that
> makes sure that md is not just any pointer but a pointer to a
> specific type. That will be important later in the program.
>
> --
> Bertel
> http://lundhansen.dk/bertel/ FIDUSO: http://fiduso.dk/



Søg
Reklame
Statistik
Spørgsmål : 177558
Tips : 31968
Nyheder : 719565
Indlæg : 6408926
Brugere : 218888

Månedens bedste
Årets bedste
Sidste års bedste