Return nothing or return void-- What exactly does C# do at the end of a void Function() call? -


consider following c# function:

void dowork() {     ... } 

the c# documentation states:

when used return type method, void specifies method does not return value.

that seems straight-forward enough and, in cases, suits fair definition.

however, many lower-level languages (i.e. c) "void" has different meaning. specifically, blocks of code must return something. therefore, void representation of null pointer representation of "nothing". in such case, not need have return statement within code because block-statement doesn't return value automatically returns null pointer.

is c# or when void function called, execute block of code , return without having pointer containing value of void?

first off, c# compiled il, final representation post-jit may differ.

with void method, method signature in il marked void, , ret opcode still exist. means, standpoint of il, "returned" value on call stack may or may not exist, never copied , used on call site. ret opcode push return value if exists, , not required exist in void returning method, in many cases, it not return anything, in low level conceptual standpoint.

however, many lower-level languages (i.e. c) "void" has different meaning. specifically, blocks of code must return something.

this not case in clr. void method can return nothing, ret opcode allowed not return anything. see opcodes.ret:

returns current method, pushing return value (if present) callee's evaluation stack onto caller's evaluation stack.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -