function-calls

Best way to detect when a function is called from the console

允我心安 提交于 2019-12-05 06:47:12
问题 I would like to know the best way to detect when a method or function is directly called through the console. As far as I currently understand, it's not possible to directly detect it on identical function calls, but using the .call() and .apply() methods of a function I can pass additional data through the this object. Given the following code structure: (function(){ var Player = {money: 0}; window.giveMoney = function(amount){ if (this.legit !== true) throw new Error("Don't try to cheat!");

Delayed Function Call

我的梦境 提交于 2019-12-04 22:13:00
What's the most elegant way of performing a delayed (and therefore also asynchronous) functional call using C++11, lambdas and async? Suggested naming: delayed_async . Reason for asking is that I want a GUI alert light to be switched off after given time (in this case one second) without blocking the main (wxWidgets main loop) thread of course. I've use wxWidgets' wxTimer for this and I find wxTimer rather cumbersome to use in this case. So that got my curious about how much more convenient this could be implemented if I instead used C++11's async 1 , 2 . I'm aware of that I need to protect

Calling C++ function from a C code

只愿长相守 提交于 2019-12-04 19:44:07
So I have looked here and here and at a few other links mentioned in the first question and I have the following code already: The .cpp file: #include "arp_piping.h" #include <string> #include <iostream> #include <stdio.h> std::string exec(char* cmd, FILE* pipe) { pipe = _popen(cmd, "r"); if (!pipe) return "ERROR"; char buffer[128]; std::string result = ""; while(!feof(pipe)) { if(fgets(buffer, 128, pipe) != NULL) result += buffer; } _pclose(pipe); return result; } The header/linker file: #ifndef ARP_PIPING_H #define ARP_PIPING_H #endif #ifdef __cplusplus #define EXTERNC extern "C" #else

C++ (nested) function call instructions - registers

那年仲夏 提交于 2019-12-04 13:42:37
问题 In C++ FAQ: Assuming a typical C++ implementation that has registers and a stack, the registers and parameters get written to the stack just before the call to g(), then the parameters get read from the stack inside g() and read again to restore the registers while g() returns to f(). regarding the nested function call void f() { int x = /*...*/; int y = /*...*/; int z = /*...*/; ...code that uses x, y and z... g(x, y, z); ...more code that uses x, y and z... } 1/ Are all implementation of C+

C# - Calling a function from static main

狂风中的少年 提交于 2019-12-04 05:16:05
问题 my question is probably very basic but I did not find an answer... I wrote a function (public checkSomething that gets 2 strings) in program.cs when I tried to call this function from static main I got this error: "An object reference is required for a non-static field, method or property 'checkSomething(string,string)' ". However,when I changed my main to Public (and not static)- there is no error. Why this happen? What is better - to have a Static main or not? Why would it even matter?

Confusion around function call resolution

元气小坏坏 提交于 2019-12-04 04:42:00
This question is inspired by this one . Consider the code: namespace ns { template <typename T> void swap(T& a, T& b) { using namespace std; swap(a, b); } } After some test with GCC, I found that swap(a, b); resolves to 1) std::swap if T has overloaded std::swap (e.g., standard container types) 2) ns::swap otherwise, leading to infinite recursion. So, it seems that the compiler will first try to find a match in the namespace ns . If a match is found, the search ends. But this is not the case when ADL comes in, in which case, std::swap is found anyway. The resolution process seems to be

Best way to detect when a function is called from the console

删除回忆录丶 提交于 2019-12-03 20:41:48
I would like to know the best way to detect when a method or function is directly called through the console. As far as I currently understand, it's not possible to directly detect it on identical function calls, but using the .call() and .apply() methods of a function I can pass additional data through the this object. Given the following code structure: (function(){ var Player = {money: 0}; window.giveMoney = function(amount){ if (this.legit !== true) throw new Error("Don't try to cheat!"); Player.money += amount; } })(); I could call the function using window.giveMoney.call({legit: true},

Function arguments push order

为君一笑 提交于 2019-12-03 12:37:19
问题 Why are function arguments pushed on the stack in right to left order? 回答1: To enable the existence of functions with a variable number of arguments, like printf. The function can extract the first one or two arguments and then use their values to deduce the total number of arguments on the stack. 回答2: The only reason is for variadic functions: the first arguments popped from the stack are the "known" ones for the function, and it can determine from them how many other arguments it should

C++ (nested) function call instructions - registers

流过昼夜 提交于 2019-12-03 08:40:29
In C++ FAQ : Assuming a typical C++ implementation that has registers and a stack, the registers and parameters get written to the stack just before the call to g(), then the parameters get read from the stack inside g() and read again to restore the registers while g() returns to f(). regarding the nested function call void f() { int x = /*...*/; int y = /*...*/; int z = /*...*/; ...code that uses x, y and z... g(x, y, z); ...more code that uses x, y and z... } 1/ Are all implementation of C++ with registers and stack? Does it mean: implementation dependent on compiler/processor/computer

How to use 'hclust' as function call in R

久未见 提交于 2019-12-03 07:58:48
问题 I tried to construct the clustering method as function the following ways: mydata <- mtcars # Here I construct hclust as a function hclustfunc <- function(x) hclust(as.matrix(x),method="complete") # Define distance metric distfunc <- function(x) as.dist((1-cor(t(x)))/2) # Obtain distance d <- distfunc(mydata) # Call that hclust function fit<-hclustfunc(d) # Later I'd do # plot(fit) But why it gives the following error: Error in if (is.na(n) || n > 65536L) stop("size cannot be NA nor exceed