0

I've scanned a lot of C++ sites but have not found an answer yet. In several pre written programs, I've noticed that a single brace "{" is used without being closed later in the program. It appears like it is used to go outside the program to get info. like looking to see if a program has the .cpp extension. Anyone ever noticed that and know what the deal is?

Dick

3
Contributors
3
Replies
4
Views
13 Years
Discussion Span
Last Post by Dick
0

Hello Dick,

Welcome to the boards.

To answer your main question, I'm not familiar with any C or C++ syntax of this sort. I have viewed a nifty document on Control Structures, and have not found anything of this type, executable. The curly brackets {} are usually defined as "block of instructions".

In greater detail, a block of instructions is a group of instructions separated by semicolons (;) but grouped in a block delimited by curly bracket signs: { and }.

If we want the statement to be a single instruction we do not need to enclose it between curly-brackets ({}). If we want the statement to be more than a single instruction we must enclose them between curly brackets ({}) forming a block of instructions.

Example:

int main() {
	int i, j, k=0;

	/*
	** Nested loop
	** Single instruction per computation
	*/
	for (i = 0; i < 2; i++)
		for (j = 0; j < 1; j++)
			k++;

	/*
	** While loop
	** Multiple instruction per computation
	*/
	while (k--) {
		j--;
		i++;
	}

	return 0;
}

With this information given, it remains unclear if a block of instructions can be opened, then not closed. Most compilers will result an error, or provide the fact that an instruction must be complete before continuing.


I hope this helps,
- Stack Overflow

0

Inside the C/C++ language, braces are always used in pairs. Can you give an example of its use, especially as you refer to a cpp extension and the like?

You aren't seeing:

extern "C" {

are you? Because if you are, there WILL be a '}' somewhere later in the code. Like:

extern "C" {

<bunch of declarations of functions>

}

0

Yeah, Chainsaw, I think you've hit it. I looked for the reverse brace but maybe I better look harder. This item shows up in a lot of my .h library stuff. I will pull up one .h and carefully check. It usually comes up just after an if not statement looking for _cplusplus and I think it said "extern". I'll be back when I know more.

Dick

---Sure enough. When you know what to look for, things are easier to find. Thanks.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.