[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] Et C spørgsmål især om pointere



On Mon, 10 Jul 2000, Niels Træholt Franck wrote:

> On 10 Jul 2000, at 14:27, Mads Bondo Dydensborg wrote:
> 
> > Hvis nu man har noget i den her stil:
> > 
> > ----------
> > struct a_t 
> > {
> >   bladr bladr...              /* ligemeget */
> >   unsigned long hostdata[0];  /* Huh? 0 Bytes? */
> > };
> > 
> > a_t * a = malloc(sizeof(a_t) + sizeof(void *)); /* + noget */
> > 
> > a->hostdata = malloc(sizeof(struct gufle));
> > ---------
> Ovenståend giver delvist mening. I din malloc sætning ville jeg nok 
> rette sizeof(a_t) + sizeof(void *)
> til 
> sizeof(a_t)
> 
> unsigned long hostdata[0] er jo en pointer (kan også skrives som 
> unsigned long *hostdata) til et endnu ikke defineret array. Jeg 
> mener en pointer er 4 byte stor. Det burde ikke være nødvendigt 
> med +sizeof(void*)

Hvis du tester vil du finde - det gjorde jeg ihvertfald - at
sizeof(unsigned long * arg) != sizeof(unsigned long arg[0]) == 0 

> 
> a->hostdata = malloc(sizeof(struct gufle));
> 
> dette vil compileren sikkert ikke brokke sig over. Men hvis struct 
> gufle ikke er af samme type som hostdata (unsigned long) vil dette 
> give problemer (med nmindre der er tale om et eller andet snedigt 
> trick i SCSI koden).

Jeg tror der er tale om adskillige snedige tricks. Eller også kan jeg ikke
se skoven for bare træer. Nogen gange kan det være svært at finde ud af
hvad der er gældende.

Mads

-- 
Mads Bondo Dydensborg.                               sslug@sslug
Unix is here to stay. The Internet is Unix, all network administrators cut 
their teeth on Unix, and many of them say they'll give up Unix when you pry
it from their cold, dead fingers.



 
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] *