declaration

Vector Initialisation in C++

六眼飞鱼酱① 提交于 2019-12-04 05:31:40
问题 I am using Vectors in my code. The line that is causing the error is as follows : vector<Node> alt_seq ; alt_seq = vector<Node>(1000); for(int j=0; j<alt_cf.getNoOfNodes(i); j++) { Node temp_node = *alt_itr; alt_itr++; alt_seq.push_back(temp_node); } The line : alt_seq.push_back(temp_node); causes a runtime error. However if I initialise the Vector with some initial size as follows: vector<Node> alt_seq(1000) ; In this case the code works fine. However I do not want to give an initial size as

Get UTF-8 in Uppercase using XDocument

寵の児 提交于 2019-12-04 05:10:29
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 lowercase. Kirill Polishchuk You can create custom XmlTextWriter , e.g.: public class

Why does one have to repeat the const specifier at definition time, if declaration as const is done somewhere else?

 ̄綄美尐妖づ 提交于 2019-12-04 05:00:40
问题 After solving this simple issue, I had to ask : -> In the H file in a class ex a const static member is defined, e.g. : class ex { const static int my_ex; }; -> In the CPP file the value is specified ex::my_ex = 32; And then one gets the error "conflicting declarations" (as well as "does not name a type"). I understand that the definition in the CPP file is also a declaration which does create a conflict seen from the linker BUT why only about the const specifier (and type) and not the static

Help with understanding C# code and porting to Objective-C

送分小仙女□ 提交于 2019-12-04 04:36:03
问题 Ok, I have this prototype that was written by someone else in C# and I'm trying to put it into Objective-C. Now, I haven't had any formal experience with C# yet, so I don't know everything about it yet. I understand what the first three variables are, but I'm running into problems with what the fourth and fifth lines (c_data) are doing. Is the fourth declaring a method and then the fifth defining it or what's happening? Thanks for your help! public class c_data { public double value; public

Function declaration order matters in c language or am I doing something wrong?

旧时模样 提交于 2019-12-04 04:35:26
问题 I get this error: arthur@arthur-VirtualBox:~/Desktop$ gcc -o hw -ansi hw1.c hw1.c: In function `main': hw1.c:27:16: warning: assignment makes pointer from integer without a cast [enabled by default] hw1.c: At top level: hw1.c:69:7: error: conflicting types for `randomStr' hw1.c:27:18: note: previous implicit declaration of `randomStr' was here While compiling this code: #include <stdio.h> #include <stdlib.h> int main(int argc, char** argv) { char *rndStr; rndStr = randomStr(FILE_SIZE); /* Do

Does C provide a way to declare an extern variable as 'read-only', but define it as writeable?

左心房为你撑大大i 提交于 2019-12-04 04:21:30
问题 I'm developing a hardware abstraction library for an embedded product using GCC C. Within the library there is a variable that should be read-only to the application that links the library, but can be modified from within the compilation unit that defines it. Is there a standard, acceptable way to declare the integer (in the library header file) that will allow the application to read the value in the variable, but tell the compiler to generate an error if any attempt is made to generate code

Static Variable Declaration (C)

孤人 提交于 2019-12-04 04:18:33
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 ? 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 the declarator appears in an expression, it designates a function or object with the scope, storage duration

error: expected declaration specifiers or ‘…’ before ‘list_node’

ぃ、小莉子 提交于 2019-12-04 04:03:10
I have a catalog.h file with this typedef struct node* list_node; struct node { operationdesc op_ptr; list_node next; }; and a parser.h with this #include "catalog.h" int parse_query(char *input, list_node operation_list); Both headers have #ifndef , #define , #endif . The compiler gives me this error: expected declaration specifiers or ‘...’ before ‘list_node’ on the parse_query line. What's the matter? I tried to put the typedef in parser.h, and it's fine. Why do I get this error when the typedef is in catalog.h? The error is this (from your comment): I had an #include "parser.h" in the

extern declaration and function definition both in the same file

核能气质少年 提交于 2019-12-04 02:51:39
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 export that we use in assembly, wherin we export a particular symbol outside of the module Any ideas? You

Is long long a type in C?

巧了我就是萌 提交于 2019-12-04 00:21:11
I know the title seems quite stupid, but I think it's worth asking. Take this declaration(or definition, maybe) for example: _Thread_local long volatile static int _Atomic const long unsigned x = 10; I used to consider long long as a type, but if it's a type name, how can so many qualifiers be inserted into it? So I consulted N1570 with this question, only to be more confused. It mentions some terms such as " type-specifier " and " type-qualifier ", and I can't find long long in "type specifiers", but isn't long long a primitive type in C? There are so many books telling me so! Clarifying not