Visualizzazione dei risultati da 1 a 6 su 6
  1. #1
    Utente di HTML.it
    Registrato dal
    Jan 2006
    Messaggi
    280

    [c] typedef

    vediamo se ho capito bene...

    scrivere typedef struct abc{
    ...
    };

    significa che poi posso creare una struttura di tipo abc nel seguente modo?

    abc struttura2;

    ??

  2. #2
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,480
    In C (non in C++) non e' cosi'. Devi scrivere

    typedef struct nodoBin {
    ...
    } NodoBin;

    e puoi scrivere

    NodoBin n;

    o anche

    typedef struct {
    ...
    } NodoBin;

    e va bene sempre

    NodoBin n;

  3. #3
    uno degli stili piu' chiari che ho visto è:

    codice:
    typedef  struct  _TuaStruttura  TuaStruttura
    
    struct  _TuaStruttura
    {
      int a;
      float b;
      .....
    };
    a questo punto:

    codice:
    TuaStruttura  *qualcosa;
    PyGTK GUI programming
    un impegno concreto: eliminare la k dalle tastiere italiane

  4. #4
    Utente di HTML.it L'avatar di eclips
    Registrato dal
    Apr 2005
    Messaggi
    48
    puoi fare anche cosi:

    typedef int index;

    struct list{
    int *buffer;
    index head;
    index tail;
    index size;
    };

    int main (void){

    struct list l;

    .
    .
    .
    }

  5. #5
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,480
    In effetti lo "stile" adottato per dichiarare un nuovo tipo di dati strutturato e un puntatore a tale tipo, e' il seguente

    codice:
    typedef struct _NUOVODATO
    {
       int a;
    } NUOVODATO, *PNUOVODATO;
    
    int main(void)
    {
       NUOVODATO struttura;
       PNUOVODATO pstruttura;
    
       struttura.a = 0;
    
       pstruttura=&struttura;
    
       return 0;
    }

  6. #6
    Potresti fare cosi':

    struct Struttura
    {
    ..Struttura_vars..
    };

    Struttura *StrPtr;

    StrPtr = new Struttura;

    StrPtr -> Struttura_vars;

    Bye

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.