scope

Scope hiding in C

a 夏天 提交于 2019-12-10 09:10:50
问题 Does C have scope hiding? For example, if I have a global variable: int x = 3; can I 'declare' inside a function or main 'another' int x? 回答1: Yes, that's how C works. For example: int x; void my_function(int x){ // this is another x, not the same one } void my_function2(){ int x; //this is also another x { int x; // this is yet another x } } int main(){ char x[5]; // another x, with a different type } 回答2: Yes but some compilers complain or can be told to complain. For gcc , use -Wshadow .

Signal handler won't see global variable

北城以北 提交于 2019-12-10 05:45:11
问题 Here's the problem: this program should receive input from stdin and count the bytes inserted; the SIGUSR1 signal whill stop the main program and will print on file standard error how many bytes have been copied when I send the SIGUSR1. That's how my teacher wants me to do this: in one terminal type cat /dev/zero | ./cpinout | cat >/dev/null while from a second terminal send signals with kill -USR1 xxxx where xxxx is the pid of cpinout. I updated my previous code: /* cpinout.c */ #include

Block scope linkage C standard

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-10 04:37:05
问题 The following identifiers have no linkage: an identifier declared to be anything other than an object or a function; an identifier declared to be a function parameter; a block scope identifier for an object declared without the storage-class specifier extern . { static int a; //no linkage } For an identifier declared with the storage-class specifier extern in a scope in which a prior declaration of that identifier is visible, if the prior declaration specifies internal or external linkage,

How to get request parameters from view scoped JSF bean?

落花浮王杯 提交于 2019-12-10 04:01:52
问题 I have the view scoped bean which should access on init (@PostConstruct) the values from request URL and store them within its lifetime. I've learned, that in order to get the values from http request , I need the following code: @ManagedProperty("#{param.x}") private int x; Which gives me the value of attribute X. However, I can do that trick only in request scoped bean. Injecting this bean via @ManagedProperty to my bean also will not work. So, how to get access to that bean in view scoped

php access array value from function return

落花浮王杯 提交于 2019-12-10 03:36:16
问题 silly php question... why cant i do this? echo Auth::getFullUser()[ 'country' ]; instead you have to do this $user = Auth::getFullUser(); echo $user[ 'country' ]; 回答1: The syntax just doesn't allow it unfortunately. AFAIK there was at one time intention to put that syntax in PHP6, but it has been dropped. 回答2: PHP grammar only allows subscript notation (i.e. ['country'] ) on the end of a variable expression (i.e. $user ) not an expression (i.e. Auth::getFullUser() ) 回答3: Poor language

Block scope, function scope and local scope in Javascript

喜你入骨 提交于 2019-12-10 03:34:38
问题 Is block scope sometimes the same as function scope ? I know function scope is for everything inside a function, but don't get what exactly a block scope is. For Javascript, is it currently recommended to use let / const instead of var for future maintenance? (This was from Airbnb Style Guide) 回答1: I'm not sure you really got your questions answered yet: Is block scope sometimes the same as function scope? I know function scope is for everything inside a function, but don't get what exactly a

Rails scope for values only between two dates

纵饮孤独 提交于 2019-12-10 03:20:48
问题 I like to have a scope in Rails for selecting only values between two dates. Here is my example: I have a model with the attribute ' startDate ' and ' endDate '. Both have the type ' date ' Now I want to select every entry from today, which is between these two dates. I made a scope looks like this. class Product < ActiveRecord::Base scope :activeDate, -> { where("? >= ? AND ? <= ?", Time.now.to_date, :saleStartDate, Time.now.to_date, :salesEndDate)} In the controller: @products = Product

Python, how can I change value of a variable in the parent scope?

☆樱花仙子☆ 提交于 2019-12-10 03:03:35
问题 for example: assginment statement will declare a new local variable. foo = 'global' def func1(): foo = 'func1' def func2(): foo = 'local variable in func2' use global declaration will use the foo in global: def func2(): global foo foo = 'global changed in func2' #changed the foo value in global scope how can I change the variable foo in func1 scope? Thanks for any help. Edit: Thank you Brandon Craig Rhodes, I finally understand your meaning. if there are more than 3 scopes nested, I can store

Can final parameters be qualified in some way to resolve naming conflicts with anonymous class members?

我只是一个虾纸丫 提交于 2019-12-10 02:50:09
问题 "Why are you doing this what is wrong with you?" notwithstanding, is there any way to accomplish this without changing the final method parameter name? private Foo createAnonymousFoo(final Bar bar) { return new Foo() { private Bar bar = SomeUnknownScopeQualifier.bar; public Bar getBar() { return bar; } public void doSomethingThatReassignsBar() { bar = bar.createSomeDerivedInstanceOfBar(); } }; } Obviously without the doSomethingThatReassignsBar call, you wouldn't need the member Bar and so on

How to scope closure's variables in CF10?

橙三吉。 提交于 2019-12-10 02:47:32
问题 Quoted from the Adobe ColdFusion 10: Using closures documentation: function helloTranslator(String helloWord) { return function(String name) { return "#helloWord#, #name#"; }; } How to scope helloWord and name properly on the return line? Are they both in Arguments scope? If that's the case, they must be unique? The Closures and functions section also mentions there are 4 more scopes on top of the already long scope search: In closure, following is the order of search for an unscoped variable