argument-passing

x86 calling convention: should arguments passed by stack be read-only?

拈花ヽ惹草 提交于 2019-12-03 03:01:11
It seems state-of-art compilers treat arguments passed by stack as read-only. Note that in the x86 calling convention, the caller pushes arguments onto the stack and the callee uses the arguments in the stack. For example, the following C code: extern int goo(int *x); int foo(int x, int y) { goo(&x); return x; } is compiled by clang -O3 -c g.c -S -m32 in OS X 10.10 into: .section __TEXT,__text,regular,pure_instructions .macosx_version_min 10, 10 .globl _foo .align 4, 0x90 _foo: ## @foo ## BB#0: pushl %ebp movl %esp, %ebp subl $8, %esp movl 8(%ebp), %eax movl %eax, -4(%ebp) leal -4(%ebp), %eax

How can I pass <arguments> to IRB if I don't specify <programfile>?

孤街浪徒 提交于 2019-12-03 02:40:39
Since: irb --help Usage: irb.rb [options] [programfile] [arguments] I know I can pass arguments to ARGV if I include a programfile eg: irb test.rb A B C where test.irb is simply "p ARGV" produces: ["a", "b", "c"] Making programfile be con in DOS... I can do following irb con A B C con(main):001:0> ARGV produces: ARGV => ["A", "B", "C"] but this is system dependent and has the side effect of echoing input :-( What i really like is something like irb -- a b c BTW: I know I can set ARGV inside irb but I my intention is to alias special == irb -rSpecialLibrary" so I can do something like: special

Efficient memoization in Python

守給你的承諾、 提交于 2019-12-02 20:42:41
I have some task to solve and the most important part at the moment is to make the script as time-efficient as possible. One of the elements I am trying to optimize is memoization within one of the functions. So my question is: Which of the following 3-4 methods is the most efficient / fastest method of implementing memoization in Python? I have provided code only as an example - if one of the methods is more efficient, but not in the case I mentioned, please share what you know. Solution 1 - using mutable variable from outer scope This solution is often shown as the example memoization, but I

pass arguments between shell scripts but retain quotes

懵懂的女人 提交于 2019-12-02 18:55:00
How do I pass all the arguments of one shell script into another? I have tried $*, but as I expected, that does not work if you have quoted arguments. Example: $ cat script1.sh #! /bin/sh ./script2.sh $* $ cat script2.sh #! /bin/sh echo $1 echo $2 echo $3 $ script1.sh apple "pear orange" banana apple pear orange I want it to print out: apple pear orange banana Use "$@" instead of $* to preserve the quotes: ./script2.sh "$@" More info: http://tldp.org/LDP/abs/html/internalvariables.html $* All of the positional parameters, seen as a single word Note: "$*" must be quoted. $@ Same as $*, but each

How to pass argument through custom url to an application

有些话、适合烂在心里 提交于 2019-12-02 15:50:03
问题 I am using windows 7 I want to pass filename as argument which I want to open through custom url. I followed link http://msdn.microsoft.com/en-us/library/aa767914(v=vs.85).aspx My python code is: import os,sys selectedFileName=(sys.argv)[1] os.startfile(selectedFileName) My registry setting is: Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\cultest] @="\"URL:cultest Protocol\"" "URL Protocol"="\"\"" [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\cultest\DefaultIcon] [HKEY

C++ Ways to pass a pointer to a temporary object (on the heap) to a function?

 ̄綄美尐妖づ 提交于 2019-12-02 10:54:29
问题 I've got a function that takes a pointer to an object of a custom class (actually pointers to a base class such that polymorphism works). Within the calling routine this object however is exclusively needed for the purpose of this call, i.e. is temporary. For example like this: class A { /** stuff */ }; class B : public A { /** stuff */ }; void doSomething( const A* const _p ) { /** stuff */ } void callingRoutine() { A* tempPointer = new B; doSomething( tempPointer ); delete tempPointer; }

C++ Ways to pass a pointer to a temporary object (on the heap) to a function?

荒凉一梦 提交于 2019-12-02 05:08:14
I've got a function that takes a pointer to an object of a custom class (actually pointers to a base class such that polymorphism works). Within the calling routine this object however is exclusively needed for the purpose of this call, i.e. is temporary. For example like this: class A { /** stuff */ }; class B : public A { /** stuff */ }; void doSomething( const A* const _p ) { /** stuff */ } void callingRoutine() { A* tempPointer = new B; doSomething( tempPointer ); delete tempPointer; } Now, since I really only need the object of type B within the call to doSomething , is there a way to do

How to pass argument through custom url to an application

雨燕双飞 提交于 2019-12-02 04:39:57
I am using windows 7 I want to pass filename as argument which I want to open through custom url. I followed link http://msdn.microsoft.com/en-us/library/aa767914(v=vs.85).aspx My python code is: import os,sys selectedFileName=(sys.argv)[1] os.startfile(selectedFileName) My registry setting is: Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\cultest] @="\"URL:cultest Protocol\"" "URL Protocol"="\"\"" [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\cultest\DefaultIcon] [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\cultest\shell] [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\cultest\shell\open]

How to check if an argument is an object (and not an array) in JavaScript

半世苍凉 提交于 2019-12-02 02:06:04
问题 After testing out instasnceof I found that it will return true if the argument is an array or an object literal. function test(options){ if(options instanceof Object){alert('yes')}//this will alert for both arrays and object literals } test({x:11})// alerts test([11])// alerts as well but I do not want it to Is there a way to test if the argument "options" is an object literal? P.S. I am creating a module that will allow the user to access its configuration options, and I want to test if the

Pass a template method as an argument

久未见 提交于 2019-12-02 01:42:49
问题 Could some one help me how to implement this code? I need to pass a function to another function: std::cout << process_time(Model::method1) << std::endl; This function gets the function as a template type and calls it on an object template <typename F> double process_time(F algorithm) { Model model; double time=0; do { // ... time += model.algorithm(arg1); } while (! stop_criteria); return time; } Note that method1 is a function template as well: template <typename T> double method1(std: