function-calls

Undefined behavior: when attempting to access the result of function call

北城余情 提交于 2019-11-29 10:11:27
The following compiles and prints "string" as an output. #include <stdio.h> struct S { int x; char c[7]; }; struct S bar() { struct S s = {42, "string"}; return s; } int main() { printf("%s", bar().c); } Apparently this seems to invokes an undefined behavior according to C99 6.5.2.2/5 If an attempt is made to modify the result of a function call or to access it after the next sequence point, the behavior is undefined. I don't understand where it says about "next sequence point". What's going on here? You've run into a subtle corner of the language. An expression of array type is, in most

How to view JavaScript function calls as they occur

心已入冬 提交于 2019-11-29 01:15:49
Is it possible to view JavaScript function calls in the browser's JavaScript console? I know you can view XHR, but can you view function calls? For example, I hover my mouse over some element on a page and a div pops up. I know there was a JavaScript function that was called to show the popup so it would be nice to be able to view this call in the console so I can see what function was called. Am I missing something or is this not possible? victorhooi So basically you want to view JS calls in real-time? The Firebug extension on Firefox offers that ( http://getfirebug.com/javascript ).

What is the scope of a defaulted parameter in Python?

孤者浪人 提交于 2019-11-28 17:54:16
When you define a function in Python with an array parameter, what is the scope of that parameter? This example is taken from the Python tutorial: def f(a, L=[]): L.append(a) return L print f(1) print f(2) print f(3) Prints: [1] [1, 2] [1, 2, 3] I'm not quite sure if I understand what's happening here. Does this mean that the scope of the array is outside of the function? Why does the array remember its values from call to call? Coming from other languages, I would expect this behavior only if the variable was static. Otherwise it seems it should be reset each time. And actually, when I tried

PHP: call_user_func_array: pass by reference issue

爷,独闯天下 提交于 2019-11-28 13:40:08
The below function generates error when a function contains referenced arguments eg: function test(&$arg, &$arg2) { // some code } Now I can not use call_user_func_array for above function, it will generate an error. How to solve this problem? I do need to use call_user_func_array . Also assume that i don't know beforehand whether they are passed by reference or passed by value. Thanks A great workaround was posted on http://www.php.net/manual/de/function.call-user-func-array.php#91503 function executeHook($name, $type='hooks'){ $args = func_get_args(); array_shift($args); array_shift($args);

'Spread' parameters in Scala?

回眸只為那壹抹淺笑 提交于 2019-11-28 12:29:27
Is there any way to call a Scala function that takes individual parameters, given an array (similar to JavaScript Spreads in ECMAScript 6)? ys = [10.0, 2.72, -3.14] f(x, ...ys); The cleanest syntax would be: f(1, ys) but that does not appear to be possible. Even f(1, ys:_*) does not work (and neither does f(ys:_*) , as the compiler reports too few parameters - only the first one is filled). Example: def f (a:Int, b:Float, c:Float, d:Float): String val x = 1 val ys = List(10.0, 2.72, -3.14) // note: non-Objects val result = f(x, ys) // intuitive, but doesn't work Use Case: injecting test data

Why is a function/method call in python expensive?

对着背影说爱祢 提交于 2019-11-28 11:18:02
In this post , Guido van Rossum says that a function call may be expensive, but I do not understand why nor how much expensive can be. How much delay adds to your code a simple function call and why? A function call requires that the current execution frame is suspended, and a new frame is created and pushed on the stack. This is relatively expensive, compared to many other operations. You can measure the exact time required with the timeit module: >>> import timeit >>> def f(): pass ... >>> timeit.timeit(f) 0.15175890922546387 That's 1/6th of a second for a million calls to an empty function;

How to call VBA-function for specifying columns in SQL TRANSFORM query?

狂风中的少年 提交于 2019-11-28 08:26:00
问题 Here is my query: PARAMETERS ... TRANSFORM ... SELECT ... ... PIVOT Mytable.type In ("Other","Info"); This is a cross query and I need to set all the column headings with this row: PIVOT Mytable.type In ("Other","Info") and now I have hard-coded the headings, Other and Info . But I want to do this dynamically. So what I want to do is to call a vba-function that returns all the headings I need. Something like this: PIVOT Mytable.type In (myVbaFunction()); So my question is: How to call a vba

How to force matlab to call a regular function rather than class method when they are overloaded?

半世苍凉 提交于 2019-11-28 08:04:57
问题 Assume I have an object X of class MyClass . MyClass has a method compute , and when I call U = compute(X,...) , matlab automatically calls the class method. However, what I actually want is to call another function also called compute whose parameters start with a MyClass object though. How do I force matlab to call this regular function rather than go into the class method? 回答1: There is no way to do this without making some changes either to the function's name or location. If you check

Undefined behavior: when attempting to access the result of function call

耗尽温柔 提交于 2019-11-28 03:32:40
问题 The following compiles and prints "string" as an output. #include <stdio.h> struct S { int x; char c[7]; }; struct S bar() { struct S s = {42, "string"}; return s; } int main() { printf("%s", bar().c); } Apparently this seems to invokes an undefined behavior according to C99 6.5.2.2/5 If an attempt is made to modify the result of a function call or to access it after the next sequence point, the behavior is undefined. I don't understand where it says about "next sequence point". What's going

Is this assembly function call safe/complete?

老子叫甜甜 提交于 2019-11-28 02:05:47
I don't have experience in assembly, but this is what I've been working on. I would like input if I'm missing any fundamental aspects to passing parameters and calling a function via pointer in assembly. For instance I'm wondering if I supposed to restore ecx , edx , esi , edi . I read they are general purpose registers, but I couldn't find if they need to be restored? Is there any kind of cleanup I am supposed to do after a call? This is the code I have now, and it does work: #include "stdio.h" void foo(int a, int b, int c, int d) { printf("values = %d and %d and %d and %d\r\n", a, b, c, d);