Guest User

Untitled

a guest
Oct 24th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. int* p = (int*)malloc(sizeof(int));
  2. *p = 42; // illegal, there isn't an int
  3.  
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7.  
  8. int* foo(void);
  9.  
  10. #ifdef __cplusplus
  11. }
  12. #endif
  13.  
  14. #include "foo.h"
  15. #include <stdlib.h>
  16.  
  17. int* foo(void) {
  18. return malloc(sizeof(int));
  19. }
  20.  
  21. #include "foo.h"
  22. #include<cstdlib>
  23.  
  24. int main() {
  25. int* p = foo();
  26. *p = 42;
  27. std::free(p);
  28. }
Add Comment
Please, Sign In to add comment