[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 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*)

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 vil mene a=b=c.

Håber det må hjælpe
Niels



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