125 questions
4
votes
0
answers
44
views
Why does using 'this' in a Java instance initializer block resolve forward reference errors? [duplicate]
Problem Description
I've encountered an interesting behavior in Java regarding forward references in instance initializer blocks. When I try to access an instance variable directly, I get a forward ...
-1
votes
3
answers
157
views
Is this an elegant way to initialize a variable for the first iteration of a loop? [closed]
This is a C program that copies its input to its output, replacing each string of one or more blanks by a single blank. I don't know what is the best way to proceed when the program starts and there ...
1
vote
2
answers
594
views
Why Does PowerShell Complain It Can't Retrieve a Variable?
I'm getting the following error message:
The variable '$dateTime' cannot be retrieved because it has not been set.
The error is generated by the line [DateTime]$dateTime in this code:
[string]$...
0
votes
2
answers
109
views
Variable initialization in Javascript
There is something that I couldn't understand. I have the following code, which its purpose is to get the total of the two arrays.
let r1;
let r2;
let total;
function totalSum(arr_1, arr_2) {
...
1
vote
1
answer
47
views
Is there a way in Java to make labels move without user influence?
I am trying to develop an application where the user moves a can back and forth on the bottom of the screen to try to catch bees as they fall. I have successfullly gotten the can movement working, but ...
0
votes
1
answer
443
views
Detect and prevent processing of sequential duplicate Tradingview webhook json
I am not very well acquainted with python, but have by much trial and error, and building upon the work of others, developed a simple working and reliable interface between Tradingview (TV) and ...
1
vote
1
answer
204
views
Why is Java forcing me to initialize my String before letting the user input the value of the String?
I'm essentially making a small, simply "twenty questions" style program, using nested if-statements to try to guess what object the user is thinking based on clarifying questions.
I'm using ...
0
votes
2
answers
973
views
Is there a reason to use zero-initialization instead of simply not defining a variable when it is going to be updated before the value is used anyway?
I came across a code example learncpp.com where they zero-initialized a variable, then defined it with std::cin:
#include <iostream> // for std::cout and std::cin
int main()
{
std::cout &...
-2
votes
1
answer
128
views
Different results when initializing a variable inside and outside for loop
I have tried a backtracking algorithm and receive different results when I initialize a variable inside and outside a for loop, but I don't understand why.
#include <stdio.h>
int a[10];
int n;
...
0
votes
1
answer
70
views
Not initialized variable in nested for js react
I am trying to create 40 cells with react , each should have a different title. For example a0 ...a9, b0 ..b9 etc. This is my code
const mapItems = () => {
let playerId = ["a", "...
0
votes
1
answer
697
views
When do instance variables get auto-initialized in Java?
Stages of instance initialization are captured for example in this question. Nevertheless, it doesn't capture the moment when the instance variable get's declared and auto-initialized.
From my test ...
0
votes
1
answer
105
views
Difference between int i(x); and int i = x; [duplicate]
I have been practicing C++ in HackerRank. There I was seeing different submissions and something new came in my sight.
someone used int i(0) in for loop like
for (int i(0), mark; i<q; ++i)
So my ...
0
votes
2
answers
162
views
Why does this C code take so long to compile and execute if the variable is not initialized? [closed]
The following C code takes so long to compile and execute.
#include <stdio.h>
int main()
{
int max;
printf("Enter a value for max: ");
scanf("%d", &max);
...
3
votes
1
answer
134
views
Perl "my $bar if 0;" vs "my $bar = undef if 0;"
The following code will return an error,
$ perl -E'sub foo { my $bar if 0; $bar++ }'
This use of my() in false conditional is no longer allowed at -e line 1.
But this code
$ perl -E'sub foo { my $bar ...
0
votes
1
answer
72
views
Declaring static initializer block before declaring variable explanation
How does this code work fine and prints 9?
public class Dog{
static {
age=9;
}
static int age=7;
}
And this code doesn't compile(illegal forward reference)? Notice I changed ...
1
vote
1
answer
3k
views
In Go, how to track down which import is causing an error which occurs upon variable initialization?
I am trying to run the main() function for a repository but am running into an intractable panic which occurs upon variable initialization:
> go run main.go
go: finding github.com/myorg/some-repo/...
1
vote
1
answer
224
views
Are uninitialized members of partially-defined static objects guaranteed initialized to 0? [duplicate]
I know that uninitialized static variables are stored in BSS and therefore guaranteed to be initialized with all 0 (for their respective data-type size).
Also, in C, static variables can be defined ...
1
vote
0
answers
50
views
Detailed Initialization Procedure class variable initializer
I saw many confusing answers about the following point :
Next, execute either the class variable initializers and static initializers of the class, or the field initializers of the interface, in ...
2
votes
1
answer
387
views
Why reference with operator = works but with constructor don't?
As far as I know the following statements are the same:
A a1(1);
A a2=1;
Header:
class A
{
public:
A(int num){}
};
But when using reference it won't compile
class B{
private:
int ...
1
vote
3
answers
3k
views
Is there a way, in C, to ensure a function is called only once without pthread_once?
In C, is there a way to ensure a function is called only once without using pthread_once?
The following works in C++ but apparently not in C because initialization of a static variable must be to a ...
7
votes
3
answers
2k
views
Can I Initialize a char[] with a Ternary?
I asked a question about it and didn't get a really clear answer, but after reading this article I started preferring const char[] to const char*.
I've come upon a difficulty when initializing with a ...
1
vote
1
answer
884
views
What Form Does the Implicitly-Declared Default Constructor Take? [duplicate]
So let's say I'm working with this toy example:
struct Foo {
int member;
};
I know that the default constructor won't default initialize member. So if I do this, member remains uninitialized: ...
1
vote
0
answers
708
views
ValueError: Tensor A must be from same graph as Tensor B
I am trying to run this ResNet with a few alterations.https://github.com/tensorflow/models/tree/master/official/resnet
After looking up the error, I understand the problem to be either :
That the ...
1
vote
1
answer
961
views
How to define an object apparently implemented as a static read-only field? (Using iText 7 to convert multi-page TIFF to PDF)
I'm writing a program in PowerShell that uses iText 7 DLLs. I use a DLL disassembly tool, IText DLLs, and iText sample/example C# code and convert the sample C# code to PowerShell code.
For example:
...
2
votes
1
answer
334
views
Why PHP is not forbidding me from initializing class properties using heredoc syntax?
I'm using PHP 7.1.11
As mentioned in the PHP manual :
Heredocs can not be used for initializing class properties. Since PHP
5.3, this limitation is valid only for heredocs containing variables.
...