Questions tagged [braces]

The symbols "{" and "}", commonly used in programming languages. Please use this tag only if the specific usage of these symbols is a relevant part of the question.

The curly brackets (or braces) "{" and "}" are special cases of brackets, along with parentheses and square brackets ("[" and "]").

Curly brackets have many uses in most programming languages, such as:

  • identify code blocks;
  • create lists and arrays;
  • pass arguments to commands in TeX.
195 questions
3
votes
1 answer

Visual Studio 2015 bracing doesn't work properly

In Visual Studio Ultimate 2013 I could write: public void Foo() And then write left brace + enter and i received: public void Foo() { | <- My cursor's position } But in Visual Studio Community 2015 if I do it too fast i will…
3
votes
1 answer

How to reformat Java from Allman to K&R with line comments using Eclipse?

I started out coding using the Allman style, with aligned braces: void foobar() { if(foo) { bar(); } } After decades I've decided I want that extra screen space; and besides, my client uses non-matched braces, so it's hard to switch back…
Garret Wilson
  • 18,219
  • 30
  • 144
  • 272
3
votes
4 answers

{$_GET['action']}(); What does mean all these braces?

Could someone please help to understand this syntaxe trick in php: enter $controller->{$_GET['action']}(); I'm talking about the {$_GET['action']}(); I'm trying to understand the mvc pattern on this blog http://r.je/mvc-in-php.html but it's realy…
3
votes
2 answers

Tcl adds curly braces when using `$` sign

set B {pc_0::!mx_0 pi::$mx_0} puts $B set A "" foreach x $B { lappend A $x } puts $A The output of this program is pc_0::!mx_0 pi::$mx_0 pc_0::!mx_0 {pi::$mx_0} It is strange that tcl adds curly braces in second output. I guess it is…
Ashot
  • 10,807
  • 14
  • 66
  • 117
3
votes
2 answers

For a structure variable,why is the initializer {21,19,3.6} same as {{21,19},3.6},but not vice-versa?

In the following example,I've illustrated this using two structures test1 and test2.The first has two elements-an integer array sized two,and a float element.The second structure has 3 elements,2 integers and one float. I initialize two structure…
Rüppell's Vulture
  • 3,583
  • 7
  • 35
  • 49
2
votes
2 answers

What is the difference between [myString length] and myString.length in objective-c?

I'm currently learning objective-c. What exactly do the square braces around things signify and is there any difference between using that and using a period (I'm from a .NET world so this would be simpler for me). Thanks.
Matt B
  • 741
  • 3
  • 10
  • 17
2
votes
0 answers

Stata randomly produces "program error: code follows on the same line as close brace" only sometimes

I have some Stata code that sometimes produces the error: program error: code follows on the same line as close brace. Other times it runs. What is strange is that the code will run, maybe 80% of the time, but then sometimes it hits this error.…
Bob
  • 127
  • 2
  • 7
2
votes
1 answer

VS Code C# braces NOT on new lines

Can't find a way to make formatters put braces on the same line. The default formatter seems to completely ignore all the settings related to new lines. Some people recommended C# FixFormat extension, but now it's deprecated and gone from the…
Foresteam
  • 23
  • 4
2
votes
1 answer

Python: Get part of string between appropriate braces and symbols

For if i have the following in a text file: { fun cake(){ "im cute" subfun notcake(){ "dont close the question!" } } fun notcute(){ "Did you just say..." } } i want to get the stuff between two braces of the fun cake(). Those particular braces, and…
Xephonine
  • 49
  • 7
2
votes
1 answer

Why is bash behaving differently when it takes argument in braces?

Input: range 6 function range { echo {0..$1} echo {0..6} if [[ $1 =~ 6 ]] then echo "Equal" fi } Output: {0..6} 0 1 2 3 4 5 6 Why is the output different whereas $1 and 6 is equal?
NobinPegasus
  • 545
  • 2
  • 16
2
votes
1 answer

How to disable IntelliJ's indentation-based brace handling?

IntellIJ 2020.2 added Indentation-based brace handling for Scala mentioned on the website here whatsnew. How do I disable this feature? I've searched for keywords "indent brace" and "brace handling" and cant see a setting that would disable it under…
user794783
  • 3,619
  • 7
  • 36
  • 58
2
votes
2 answers

Eclipse Java Formatter. New line before curly braces, but not after

we have here at work a very strange coding convention, and I didn't managed to setup the Java Formatter in Eclipse right to do what I want. The convention says: Before a curly brace "{" there should always be a new Line [UPDATE] There is no rule…
Asturio
  • 535
  • 7
  • 23
2
votes
3 answers

Scoping rules in Java

Can someone help me understand the scoping rules in Java? This is clearly not valid: { int i = 0; System.out.println(i); // fine, of course } System.out.println(i); // syntax error i is declared within the {}, and it's…
Matthew Gilliard
  • 9,298
  • 3
  • 33
  • 48
2
votes
1 answer

Substituting braces {} with quotes "

I want to replace braces {} with quotes ". I tried the following code, the problem is that the \ appaers in the string and I can not delete it. Code used: makebib <- function(string){ # replace { by " string <- gsub("\\{",'"',string) #…
2
votes
2 answers

c++ - initializing an array member with aggregate initialization

With this code: struct Structure { int a; char b[4]; }; void function() { int a = 3; char b[] = {'a', 'b', 'c', 'd'}; } Can I initialize Structure with the values of a and b using aggregate initialization? I tried Structure{a, b},…