fork download
  1. #include <stdarg.h>
  2.  
  3. /* Some definitions and declaration to make the code work */
  4. #define IO 01
  5. #define USART 02
  6. #define LCD 03
  7. #define set_portB 1
  8.  
  9. struct __port__ { int set; };
  10. struct __io__ {
  11. struct __port__ portB;
  12. struct __port__ portC;
  13. struct __port__ portD;
  14. };
  15. typedef struct __io__ io;
  16. typedef struct __io__ lcd;
  17. typedef struct __io__ usart;
  18.  
  19. void init_peripheral(int ID, ...) {
  20. va_list device;
  21. va_start(device, ID);
  22. io* temp;
  23. (*temp).portB.set = set_portB; // NOTE: dereferencing uninitialized pointer!
  24.  
  25. if (ID == IO) {
  26. io* config_io;
  27. config_io = va_arg(device, io*);
  28. // ...
  29. } else if (ID == LCD) {
  30. lcd *config_lcd;
  31. config_lcd = va_arg(device, lcd*);
  32. // ...
  33. } else if (ID == USART) {
  34. usart *config_usart;
  35. config_usart = va_arg(device, usart*);
  36. // ...
  37. }
  38. va_end(device);
  39. }
  40.  
  41. int main() { return 0; }
Success #stdin #stdout 0.01s 1672KB
stdin
Standard input is empty
stdout
Standard output is empty