   union parameters
  Hi folks.In C,Why can't I use a union type as a parameter for a function?   
  Can we see the source code please?   ;  Ehm, I have the source code elsewhere, but for example:#include <stdio.h>#include <stdbool.h> // To use bool type in Cstruct car{    char brand[30];    short max_speed; // Miles per hour    char seat_capacity; // Use as integer.};struct truck{    char brand[30];    long weight; // Pounds.    long storage_capacity; // Cubic meters    };union machine{    struct truck myTrucky;    struct car myCary;    bool is_car; // Else is truck;}mach;union machine TakeTruckOrCar(union machine m);int main(){    union machine myMachine = TakeTruckOrCar(mach);   return 0;    }union machine TakeTruckOrCar(union machine m){    if(m.is_car){   m.car.brand = "beyota";   m.car.max_speed = 250;   m.car.seat_capacity = 100;    }    else{   m.truck.brand = "Pergout";    m.truck.weight = 967;   m.truck.storage_capacity = 14;    }    return m;}mingw (for Wikndows XP SP3) GCC would complain that incomplete type is not possible for function parameter. If I recall correctly, it also warns about the function prototype returning incomplete type and having incomplete type parameters.[Edited by - gasto on April 6, 2010 5:48:43 PM];  I think you forgot some code.anyway, this should work:typedef union{    int a;    float b;} MyUnion;void myFunction( MyUnion poop ){};  Thanks, the problem with your approach though is that it restricts to global variable definitions.   ;Quote:Original post by gastoThanks, the problem with your approach though is that it restricts to global variable definitions.I didn't declare any global variables.  That's a typedef: a declaration of a type, it's not an instance of that type.-me   ;  You are right, sorry for my confusion.I will test and see if typedefing it works, although I wouldn't understand why GCC complains about it and halts compilation (AKA throws an error).   ;  Once the code you posted is corrected for obvious syntax errors (missing ;'s, keywords, etc.) it compiles fine with gcc 3.4.4.#include <stdio.h>#include <stdbool.h> // To use bool type in Cstruct car{    char brand[30];    short max_speed; // Miles per hour    char seat_capacity; // Use as integer.};struct truck{    char brand[30];    long weight; // Pounds.    long storage_capacity; // Cubic meters    };union machine{    struct truck myTrucky;    struct car myCary;    bool is_car; // Else is truck;}mach;union machine TakeTruckOrCar(union machine m);int main(){    union machine m = TakeTruckOrCar(mach);   return 0;    }union machine TakeTruckOrCar(union machine m){    if(m.is_car){   strcpy(m.myCary.brand, "beyota");   m.myCary.max_speed = 250;   m.myCary.seat_capacity = 100;    }    else{   strcpy(m.myTrucky.brand, "Pergout");    m.myTrucky.weight = 967;   m.myTrucky.storage_capacity = 14;    }    return m;};Quote:Original post by SiCraneOnce the code you posted is corrected for obvious syntax errors (missing ;'s, keywords, etc.) it compiles fine with gcc 3.4.4.*** Source Snippet Removed ***Thanks, I will have to check this bit of code I just created, because I tested other similar code.  Will check and report later. Thanks again.   ;  Do you realise that by this definition, a machine is either a truck OR a car OR a bool! I.e. it is one of three possible things!union machine{    struct truck myTrucky;    struct car myCary;    bool is_car; // Else is truck;}mach;