Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

return value is undefined in C

Tags:

c

Not sure if I'm overthinking for this, but how would I return something undefined when the parameter is not in the range that needs to be?

I'm trying to do:

uint64_t function(uint64_t Value, uint64_t N) {
   uint64_t result = 0;

   if (N > 0){
     //do something;
     return result;
   }
   else{
     return result is undefined;
   }
}

How do I return N is undefined?

like image 488
Tavo Avatar asked Jun 26 '26 18:06

Tavo


1 Answers

One solution is to return a status and use an OUT parameter like so:

bool function(uint64_t Value, uint64_t N, uint64_t *result) {

   if (N > 0){
     //do something;
     *result = 31337;
     return true;
   }
   else{
     return false;
   }
}

Then when you call this function you check that the function returns true before using the result.

like image 103
caskey Avatar answered Jun 29 '26 08:06

caskey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!