IMerin
IMerin

Reputation: 75

Does a function that returns a variable still run without assignment?

In this specific example, the code would be down_interruptible(&semaphore). down_interruptible returns an integer. Should the function still run appropriately despite no assignment for the return value, or does the lack of assignment cause the statement to be skipped altogether?

Upvotes: 0

Views: 70

Answers (2)

quantdev
quantdev

Reputation: 23793

You are free to ignore a returned value in C (although it is considered bad practice in some cases, e.g. when an error code is returned), the function call will still be made.

Generally speaking, compiler are not permitted to remove code having observable side effects. (So technically speaking, if your function does nothing, the compiler could omit the call)

Upvotes: 1

ByoTic
ByoTic

Reputation: 103

Yes, unless it doesn't make any difference and the compiler finds it handy to optimize the program and cancel the function's call.

Upvotes: 0

Related Questions