variable-assignment

Segmentation fault(core dumped) variable assignment

蓝咒 提交于 2019-12-11 05:09:14
问题 I have a program written in C++, compiled with G++, running in Ubuntu 13.04 32 bits, that is giving the following error: "Segmentation fault (core dumped)". int main(int argc, char *argv[]){ printf("1\n"); int x = 0 , y = 0, count = 0; printf("2\n"); char c; printf("3\n"); int n_frames = (atoi(argv[1]) - 1); printf("4\n"); int windowSize = WINDOW_SIZE; // WINDOW_SIZE is a define printf("5\n"); // And the program go on.... long double frames[n_frames][377]; long double dis_frames[n_frames -

Multiple variable assignment using 'read' works in bash v4.3.48 and does not in v4.4.7

我们两清 提交于 2019-12-11 04:33:09
问题 I'm using two distros which use bash v4.3.48 and v4.4.7. read VAR1 VAR2 <<< $(echo 0 ; echo 1) echo $VAR2 For bash v4.3.48, the result of commands above is $VAR2 has value 1. But, with bash 4.4.7, $VAR2 is null. To get the same result, in 4.4.7, I must modify the script: read VAR1 VAR2 <<< $(echo -n $(echo 0 ; echo 1) ) I don't know my (previous) script was wrong or there're changes in the newer bash. 回答1: It looks like the behavior when expanding <<< $( ) has changed slightly. Normally, when

PL/pgSQL: accessing fields of an element of an array of custom type

空扰寡人 提交于 2019-12-11 04:11:38
问题 I've defined a custom type: create type pg_temp.MYTYPE as (f1 int, f2 text); Then, inside a function or a block, I've declared an array of such type: declare ax MYTYPE[]; I can access an element through the familiar syntax ax[1].f1 , but just for reading it. When I use the same syntax for setting the field, I get a syntax error. create type pg_temp.MYTYPE as (f1 int, f2 text); do $$ declare x MYTYPE; declare ax MYTYPE[]; declare f int; begin x.f1 = 10; x.f2 = 'hello'; --assigning an element:

declaration as condition - adding parentheses causes errors

十年热恋 提交于 2019-12-11 03:32:42
问题 Why is this ok: if(int i = 1) { } ...whereas the following produces errors? if((int i = 1)) { } Under g++ (4.4.5) the latter gives: test.cpp:7: error: expected primary-expression before ‘int’ test.cpp:7: error: expected ‘)’ before ‘int’ test.cpp:9: error: expected ‘)’ before ‘else’ test.cpp:13: error: expected primary-expression before ‘}’ token test.cpp:13: error: expected ‘;’ before ‘}’ token Incidentally, the reason I'm asking is because of this answer: Seeing what class an object is I'm

What types of languages allow programmatic creation of variable names?

淺唱寂寞╮ 提交于 2019-12-11 03:31:57
问题 This question comes purely out of intellectual curiosity. Having browsed the Python section relatively often, I've seen a number of questions similar to this, where someone is asking for a programmatic way to define global variables. Some of them are aware of the pitfalls of exec , others aren't. However, I've recently been programming in Stata, where the following is common: local N = 100 local i = 1 foreach x of varlist x1 - x`N' { local `x' = `i' * `i' ++i } In Stata parlance, a local

Why is it impossible to assign constant properties of JavaScript objects using the const keyword?

耗尽温柔 提交于 2019-12-11 03:30:06
问题 First, I had asked is it possible: How to create Javascript constants as properties of objects using const keyword? Now, I gotta ask: why? The answer to me seems to be 'just because', but it would be so useful to do something like this: var App = {}; // want to be able to extend const App.goldenRatio= 1.6180339887 // throws Exception Why can constants set on an activation object work but not when set on they are set on any other? What sort of damage can be done if this were possible? What is

Basic assignment of swig wrapped variables fails

一个人想着一个人 提交于 2019-12-11 03:24:13
问题 I created a lua module with a very large number of wrapped C++ classes using swig. The wrappers are generated and compiled (with -Wall) without any issues. However, in a couple of places that I've found, I run into the following issue: basic assignment of member data fails. If I run: Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio > require('myModule') > a = myModule.ClassA() I can then verify that the metatable attached to "a" contains all of its member data (in this case fields "b" and

Multiple inline assignments in one statement in c#

荒凉一梦 提交于 2019-12-11 02:19:44
问题 Obviously the following is totally fine in c#; int a; int b = a = 2; Is it possible to do multiple variable assignments in c# in a single statement? i.e. something like; int a = (int b = 2); 回答1: If we look at: int a; int b = a = 2; That is essentially a=2; then b=a; (but without an extra eval). So we can get similar by reversing the order: int a = 2, b = a; However: I would say take this a bit hesitantly: please also prioritise readability. 回答2: Not as far as I know. The only variation I

Problem with assigning elements of a class array to individual variables in MATLAB

霸气de小男生 提交于 2019-12-11 01:26:23
问题 This is a bit of a duplicate of this question, this question, and this question, however those solutions don't work, so I'm asking mine. I've got an array of locally defined classes and I'd like to assign it to multiple, individual variables. This pattern doesn't work: %a is 2x1 of MyClass temp = mat2cell(a); [x,y] = temp{:}; %throws: ??? Insufficient number of outputs from right hand side of equal sign to satisfy assignment. Because temp is a single cell, with my 2x1 array in one cell,

shortcut to existentially define variable in javascript

随声附和 提交于 2019-12-11 01:06:27
问题 To avoid clobbering existing variables, I have code like this window.x = typeof x != "undefined" ? x : {} Which seems like a very long winded way to define something, but necessary to avoid console errors. I tried this out instead, and it seems to work ok. Is it ok to define a variable like this? window.x=window.x||{} Or even in the global scope... x=this.x||{} 回答1: If you use this construct: window.x=window.x||{} And x is defined but has a falsy value (zero, the empty string, null, NaN,