Guest User

Untitled

a guest
May 20th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. double pop(void)
  2. {
  3. if(sp > 0)
  4. return val[--sp];
  5. else {
  6. printf("error: stack emptyn");
  7. return 0.0;
  8. }
  9. }
  10.  
  11. int pop(double* outval)
  12. {
  13. if(outval == 0) return -1;
  14. if(sp > 0)
  15. *outval = val[--sp];
  16. else {
  17. printf("error: stack emptyn");
  18. return -1;
  19. }
  20. return 0;
  21. }
  22.  
  23. TRY {
  24. ...
  25. THROW(MY_EXCEPTION);
  26. /* Unreachable */
  27. } CATCH(MY_EXCEPTION) {
  28. ...
  29. } CATCH(OTHER_EXCEPTION) {
  30. ...
  31. } FINALLY {
  32. ...
  33. }
  34.  
  35. int pop(double *dptr)
  36. {
  37. if(sp > 0) {
  38. *dptr = val[--sp];
  39. return 0;
  40. } else {
  41. return 1;
  42. }
  43. }
  44.  
  45. double pop(int *error)
  46. {
  47. if(sp > 0) {
  48. return val[--sp];
  49. *error = 0;
  50. } else {
  51. *error = 1;
  52. printf("error: stack emptyn");
  53. return 0.0;
  54. }
  55.  
  56. int pop(double *d)
  57. {
  58. if(sp > 0) {
  59. *d = val[--sp];
  60. return 0;
  61. } else {
  62. return 1;
  63.  
  64. }
  65. }
  66.  
  67. struct stack{
  68. double* pData;
  69. uint32 size;
  70. };
  71.  
  72. struct popRC{
  73. double value;
  74. uint32 size_before_pop;
  75. };
  76.  
  77. popRC pop(struct stack* pS){
  78. popRC rc;
  79. rc.size=pS->size;
  80. if(rc.size){
  81. --pS->size;
  82. rc.value=pS->pData[pS->size];
  83. }
  84. return rc;
  85. }
  86.  
  87. popRC rc = pop(&stack);
  88. if(rc.size_before_pop!=0){
  89. ....use rc.value
  90.  
  91. std::pair<something,bool>
  92.  
  93. std::set<...>::insert
  94. std::map<...>::insert
  95.  
  96. enum{FAIL,SUCCESS};
  97.  
  98. int empty(struct stack* pS){
  99. return (pS->size == 0) ? 1 : 0;
  100. }
  101.  
  102. int ok=0;
  103.  
  104. do
  105. {
  106. /* Do stuff here */
  107.  
  108. /* If there is an error */
  109. break;
  110.  
  111. /* If we got to the end without an error */
  112. ok=1;
  113.  
  114. } while(0);
  115.  
  116. if (ok == 0)
  117. {
  118. printf("Fail.n");
  119. }
  120. else
  121. {
  122. printf("Ok.n");
  123. }
Add Comment
Please, Sign In to add comment