Skip to main content
added 20 characters in body
Source Link

Polymorphism is a really good feature that C++ provides for free. However, there are other aspects that you may need to consider when choosing a compiler. There is an alternative for polymorphism in C but its use can cause some raised eyebrows. Its the variadic function, please refer to Variadic function tutorial.

In your case it would be something like

enum serialDataTypes
{
 INT =0,
 INT_P =1,
 ....
 }Arg_type_t;
....
....
void transmit(Arg_type_t serial_data_type, ...)
{
  va_list args;
  va_start(args, serial_data_type);
  
  switch(serial_data_type)
  {
    case INT: 
    //Send integer
    break;
    
    case INT_P:
    //Send data at integer pointer
    break;
    ...
   }
 va_end(args);
}

I like Phillips approach but it litters your library with a lot of calls. With the above the interface is clean. It does have its drawbacks and ultimately its a matter of choice.

Polymorphism is a really good feature that C++ provides for free. However, there are other aspects that you may need to consider when choosing a compiler. There is an alternative for polymorphism in C but its use can cause some raised eyebrows. Its the variadic function, please refer to Variadic function tutorial.

In your case it would be something like

enum serialDataTypes
{
 INT =0,
 INT_P =1,
 ....
 }Arg_type_t;
....
....
void transmit(Arg_type_t serial_data_type, ...)
{
  va_list args;
  va_start(args, serial_data_type);
  
  switch(serial_data_type)
  {
    case INT: 
    //Send integer
    break;
    
    case INT_P:
    //Send data at integer pointer
    break;
    ...
   }
}

I like Phillips approach but it litters your library with a lot of calls. With the above the interface is clean. It does have its drawbacks and ultimately its a matter of choice.

Polymorphism is a really good feature that C++ provides for free. However, there are other aspects that you may need to consider when choosing a compiler. There is an alternative for polymorphism in C but its use can cause some raised eyebrows. Its the variadic function, please refer to Variadic function tutorial.

In your case it would be something like

enum serialDataTypes
{
 INT =0,
 INT_P =1,
 ....
 }Arg_type_t;
....
....
void transmit(Arg_type_t serial_data_type, ...)
{
  va_list args;
  va_start(args, serial_data_type);
  
  switch(serial_data_type)
  {
    case INT: 
    //Send integer
    break;
    
    case INT_P:
    //Send data at integer pointer
    break;
    ...
   }
 va_end(args);
}

I like Phillips approach but it litters your library with a lot of calls. With the above the interface is clean. It does have its drawbacks and ultimately its a matter of choice.

Source Link

Polymorphism is a really good feature that C++ provides for free. However, there are other aspects that you may need to consider when choosing a compiler. There is an alternative for polymorphism in C but its use can cause some raised eyebrows. Its the variadic function, please refer to Variadic function tutorial.

In your case it would be something like

enum serialDataTypes
{
 INT =0,
 INT_P =1,
 ....
 }Arg_type_t;
....
....
void transmit(Arg_type_t serial_data_type, ...)
{
  va_list args;
  va_start(args, serial_data_type);
  
  switch(serial_data_type)
  {
    case INT: 
    //Send integer
    break;
    
    case INT_P:
    //Send data at integer pointer
    break;
    ...
   }
}

I like Phillips approach but it litters your library with a lot of calls. With the above the interface is clean. It does have its drawbacks and ultimately its a matter of choice.