declaration

php: pushing to an array that may or may not exist

孤街浪徒 提交于 2019-12-10 01:52:37
问题 I want to create an array with a message. $myArray = array('my message'); But using this code, myArray will get overwritten if it already existed. If I use array_push , it has to already exist. $myArray = array(); // <-- has to be declared first. array_push($myArray, 'my message'); Otherwise, it will bink. Is there a way to make the second example above work, without first clearing $myArray = array(); ? 回答1: Check if the array exists first, and if it doesn't, create it...then add the element,

Static Variable Declaration (C)

三世轮回 提交于 2019-12-09 17:29:42
问题 Are the following two static variable declarations equivalent? 1. static int var1; static int var2; static int var3; 2. static int var1, var2, var3; More specifically, in case 2, will all variables be static , or just var1 ? 回答1: Yes the declarations in case 1 and 2 are identical. We can see this by going to the draft C99 standard section 6.7.5 Declarators which says ( emphasis mine going forward ): Each declarator declares one identifier, and asserts that when an operand of the same form as

Get UTF-8 in Uppercase using XDocument

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-09 16:41:03
问题 I need to have XML encoding and version at the top of my XML document which I am making with XDocument . I have this but it is in lowercase, and it needs to be in uppercase. What do I need to do? I declare a new XML document using the XDocument class called 'doc'. I save this to a file using doc.Save(); . I have tried: doc.Declaration.Encoding.ToUpper(); Declaring a new XDeclaration Typing the Encoding in uppercase and setting my doc.Declaration to my XDeclaration . It still comes through in

extern declaration and function definition both in the same file

余生长醉 提交于 2019-12-09 14:52:13
问题 I was just browsing through gcc source files. In gcc.c , I found something like extern int main (int, char **); int main (int argc, char **argv) { Now my doubt is extern is to tell the compiler that the particular function is not in this file but will be found somewhere else in the project. But here, definition of main is immediately after the extern declaration. What purpose is the extern declaration serving then? It seems like, in this specific example, extern seems to be behaving like

How do I write a TypeScript declaration file for an external commonjs module that has constructor?

北战南征 提交于 2019-12-09 12:55:42
问题 PLEASE SEE MORE DETAILED QUESTION: How do I write a TypeScript declaration file for a complex external commonjs module that has constructor, such as imap? I write TypeScript for a Node.js app, and I want to write a TypeScript declaration file for a javascript module (available from npm) that has a constructor at the module level. Here is a simplified version of the relevant code, in file a.js : function A(config) { this.state = 'constructed'; } A.prototype.update = function() { this.state =

Encoding in XML declaration python

帅比萌擦擦* 提交于 2019-12-09 10:30:46
问题 I have created an XML file using python. But the XML declaration has only version info. How can I include encoding with XML declaration like: <?xml version="1.0" encoding="UTF-8"?> 回答1: >>> from xml.dom.minidom import Document >>> a=Document() >>> a.toprettyxml(encoding="utf-8") '<?xml version="1.0" encoding="utf-8"?>\n' or >>> a.toxml(encoding="utf-8") '<?xml version="1.0" encoding="utf-8"?>' you can set the encoding for the document.writexml() function in the same way. 来源: https:/

function vs variable declaration in C++

喜夏-厌秋 提交于 2019-12-09 08:41:11
问题 This code works: std::ifstream f(mapFilename.c_str()); std::string s = std::string(std::istreambuf_iterator<char>(f), std::istreambuf_iterator<char>()); ParseGameState(s); Whereby mapFilename is an std::string and void ParseGameState(const std::string&); . And this does not: std::ifstream f(mapFilename.c_str()); std::string s(std::istreambuf_iterator<char>(f), std::istreambuf_iterator<char>()); ParseGameState(s); This is the error: game.cpp: In member function ‘int Game::LoadMapFromFile(const

Objective-c basics: Object declared in MyAppDelegate not accessible in another class

萝らか妹 提交于 2019-12-09 07:25:13
问题 I have an object declared in my app delegate: @interface MyAppDelegate : NSObject <UIApplicationDelegate> { ClassName *className; } In another class, I include the app delegate: #import "MyAppDelegate.h" @implementation AnotherClass -(void)doMethod { [className doClassNameMethod]; } This fails at compile time due to className being undeclared. Shouldn't it be accessible, since I've included the MyAppDelegate, where className is declared? I need AnotherClass.doMethod to be accessing the same

Why can't you declare a variable inside the expression portion of a do while loop?

南楼画角 提交于 2019-12-09 05:00:54
问题 The following syntax is valid: while (int i = get_data()) { } But the following is not: do { } while (int i = get_data()); We can see why via the draft standard N4140 section 6.4 : 1 [...] condition : expression attribute-specifier-seq opt decl-specifier-seq declarator = initializer-clause attribute-specifier-seq opt decl-specifier-seq declarator braced-init-list 2 The rules for conditions apply both to selection-statements and to the for and while statements (6.5). [...] and section 6.5 1

How declaration of variables behave?

偶尔善良 提交于 2019-12-09 03:59:04
问题 #include<stdio.h> #include<conio.h> int main(){ char i; int c; scanf("%i",&c); scanf("%c",&i);// catch the new line or character introduced before x number printf("%i",i);// value of that character getch(); return(0); } The program will behave in the same way with the next variable declarations instead of the above variable declaration: this: int c; int *x; int i; or this: int *x; int c; int i; And only this way: c variable and a x pointer before the i variable. I know that those last