Question

I have a question about NetBios NCB (Network Control Block).I wonder why we can use this syntax, as shown example below, if the structure doesn't have any pointers.

UCHAR reset( NCB *block ) {
    block->ncb_command = NCBRESET;
    block->ncb_lana_num = 2;
    block->ncb_lsn = 0;
    block->ncb_num = 0;
    Netbios(block);
    return block->ncb_retcode;
}



int main()
{
   NCB blok;
   UCHAR err;

   printf ( "reset:");
   err = reset(&block);
   if ( err != NRC_GOODRET ) {
   printf ( "ERROR %x\n" , err ) ;
   } 
   else {
   printf ( "SUCCEED ! (%x)\n", err) ;
   };
}

The structure of NCB looks like this:

typedef struct _NCB {
   UCHAR  ncb_command;
   UCHAR  ncb_retcode;
   UCHAR  ncb_lsn;
   UCHAR  ncb_num;
   PUCHAR ncb_buffer;
   WORD   ncb_length;
   UCHAR  ncb_callname[NCBNAMSZ];
   UCHAR  ncb_name[NCBNAMSZ];
   UCHAR  ncb_rto;
   UCHAR  ncb_sto;
   void   (CALLBACK *ncb_post)( struct *NCB);
   UCHAR  ncb_lana_num;
   UCHAR  ncb_cmd_cplt;
   UCHAR  ncb_reserve[X];
   HANDLE ncb_event;
} NCB, *PNCB;

sorry for my English.

Was it helpful?

Solution

The -> syntax is used on block because block is a pointer (its type is NCB*, which means "pointer to NCB").

Whether or not the NCB structure contains any pointers as fields does not matter because block->ncb_command does not dereference the ncb_command field - it dereferences block, which is a pointer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top