address nameReg = 0x72ba7d8e73fe8eb666ea66babc8116a41bfb10e2;
nameReg.call("register", "MyName"); //1
nameReg.call(bytes4(sha3("fun(uint256)")), a); //2
if(!nameReg.call.value(10)){throw;} //3
Here it says,
Furthermore, to interface with contracts that do not adhere to the ABI, the function call is provided which takes an arbitrary number of arguments of any type. These arguments are padded to 32 bytes and concatenated. One exception is the case where the first argument is encoded to exactly four bytes. In this case, it is not padded to allow the use of function signatures here.
- Are 1 and 2 legal?
- Does it mean that 2 is illegal?
- What does the 3 mean?
"register"and"MyName"are padded to 32 bytes, whereas in 2,ais concatenated directly onto the 4-bytebytes4(sha3("fun(uint256)"))– Tjaden Hess Sep 23 '16 at 17:09calldoes not return a contract function's return value: it only returns did the function encounter an exception or not. – eth Mar 07 '21 at 21:38(bool success, bool returnBytes) = addr.call{...}(abi.encodeWithSignature(...), ...)is the new recommended way to (1) call functions without throwing if the function cannot be called, and (2) send payment to payable functions. So I'm pretty sure chriseth's comment aboutcallonly applies to the older versions. – Luke Hutchison Dec 14 '21 at 10:48