[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [CPROG] forskel på int og float/double pointere?



root wrote:
> 
> Er der principiel forskel på pointere til int og til float/double?
> 
> int* pInt;
> (*pInt) = 4;
> 
> går uden problemer. Men :
> 
> double* pDouble;
> (*pDouble) = 0.0;
> 
> o.l. giver segmentation fault. Hvad sker der?

Problemet er en C-klassiker!
Du har ikke allokeret et område til dine værdier, du har kun pegeren.
At det nogle gange går godt, er bare fordi du er "heldig". Du får nok
korrumperet en anden værdi, så problemet opstår bare senere og så er det
næsten umuligt at finde ud af hvorfor den anden værdi er blevet
korrumperet.

Pegere skal altid pege på noget veldefineret. Enten ved brug af adresse
operatoren & på en variabel af den givne type eller også ved at allokere
dynamisk data fx. vha. malloc.

PS. Jeg kan ikke lide at nogen roder som 'root' på en
linux/unix-maskine, med mindre der er nogen god grund til det! 

/Egon Andersen


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:08 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *