Non-void function used in void context? - function

I am using SystemVerilog. My code is:
function write_pixel_data(datastr ds);
/* some stuff here... but no return */
endfunction
then i am calling my function like:
write_pixel_data(someval);
And i get the vcs warning:
Warning-[SV-NFIVC] Non-void function used in void context.
But i am not returning anything, i know i can cast the function call to void to get rid of the warning. But why it gives this warning??!!
Thanks.

If you haven't declared the function as void and you call it without assigning the return value to anything, you'll see this error. Simple fix:
function void write_pixel_data(datastr ds);
/* some stuff here... but no return */
endfunction
Careful though, you can't do anything that 'takes time' in a function. You'll need a task for that.

A function declared with an implicit type returns logic. You must explicitly declare the return type to be void if that is your intention.

Related

Function<String, int> in Dart?

I have a function with a callback void doSth(Function callback), however I would like to specify the parameters and return value of the callback like in Java.
Is this possible in Dart?
(I can't use Future here)
void doSth(String Function callback(int /* type for parameter */ ))
See also https://www.dartlang.org/guides/language/effective-dart/design#prefer-inline-function-types-over-typedefs

Where would noop be used in Ceylon

I am playing around with this beautiful language and saw a function called noop.
As the documentation says it's a void function that does nothing!!
So why would I use a function that does nothing? Is it for adding "Nop" in assembly (for pipeline etc) but then this would be too low-level wouldn't it?
noop() can take the place of any void (or Anything returning) function. So it's useful to use as a value if you are calling a function or creating an object that requires you to pass in an event handler or callback function, but you aren't interested in responding to the event.
noop() is also useful as the default value of an an optional parameter of a function, for example:
void foo(void bar(Integer i) => noop(i)) {}
Or:
void foo(Anything(Integer) bar = noop) {}

Can I safely pass null to Function.apply in place of thisArg argument?

To make public API of SWF more reliable, I usually wrap callbacks in closure with try/catch block:
private function addCallback(functionName:String, closure:Function):void {
ExternalInterface.addCallback(functionName, wrapEventHandler(closure));
}
private function wrapEventHandler(closure:Function):Function {
var self:Main = this;
return function(...arguments):* {
try {
return closure.apply(self, arguments);
} catch (error:Error) {
// Print error report here
}
}
}
When exception occurs in 'closure', error report will be printed.
I noticed that it works fine even when using 'null' instead of 'self':
closure.apply(null, arguments);
Is it safe to use 'null' in this case?
Callback I register with ExternalInterface aren't static functions; they use Main's class fields.
It works just fine with null, NaN and self. I couldn't find any problems with using NaN/null.
Passing the this argument to apply() is optional, and the parameter default value is NaN.
Parameters
thisArg:* (default = NaN) — The object to which the function is
applied.
Likewise with, call():
You can pass the value null for the thisObject parameter to invoke a
function as a regular function and not as a method of an object.
For example, the following function invocations are equivalent:
Math.sin(Math.PI / 4)
Math.sin.call(null, Math.PI / 4)

ActionScript - Receiving Name of Calling Function or Constructor?

long shot: is it possible to get the name of a calling function or the constructor from the called function? is it possible to determine the previous function of the thread?
i would like to call some setter functions from my constructor and have my setter functions determine if it was the constructor that called them.
currently, i'm setting a boolean for this functionality, but perhaps there is another way?
public function Constructor(myNumber:Number)
{
this.myNumber = myNumber;
}
public function set myNumber(value:Number):void
{
myNumberProperty = value;
//if constructor called this, return;
//else do some other stuff;
}
Quote from liveDocs:
Unlike previous versions of ActionScript, ActionScript 3.0 has no arguments.caller property. To get a reference to the function that called the current function, you must pass a reference to that function as an argument. An example of this technique can be found in the example for arguments.callee.
It was in AS2.0... It unfortunately throws an error if done in AS3.0.
Technically, you should be able to do this by generating an error and getting its stack trace. The constructor will have to be on that stack trace.
try
{
throw new Error();
}
catch (e:Error)
{
// parse this for the constructor name
trace(e.getStackTrace());
}
That would be for detecting where a function call came from...
I would still go for your solution (setting the flag), as it's more oop and probably far faster in terms of performance.

what is the point of void in AS3

Simple question here, when void follows a function in AS3 what is it doing?
public function sayGoodbye():void { trace("Goodbye from MySubClass");}
void type indicates to the compiler that the function you have written will not return any value, in the other side if you indicate other type T than void the compiler expect that you return T.
Ex:
function foo(a:int):int { // here the compiler expect that somewhere
// in your function you return an int
return a;
}
void means that it has no return value. I.e., you can't use it in an expression.
void specifies that the function will return no value, or, to be more exact, the special undefined value type. Note that the function return can be used in an expression and it is the unique value of the undefined type.
In actionscript 3 to conform to the strict mode you need to specify variable types and function return types in order for the compiler to know what types to expect and to optimize your application.