Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

return a scope in C++

Tags:

c++

gcc

I encountered the following code in a file (looks like header file) iomanip of gcc 4.5.1:

inline _Setbase  
setbase(int __base)  
{ return { __base }; }  

what is the language definition of returning a scope (block)?

like image 935
Boaz Avatar asked Jun 06 '11 09:06

Boaz


People also ask

What is the scope of return statement?

When a function has a return statement in other blocks, the compiler adds a new variable and returns that value before returning from that function.

What is return value in C?

A return statement ends the execution of a function, and returns control to the calling function. Execution resumes in the calling function at the point immediately following the call. A return statement can return a value to the calling function.

What happens when a variable goes out of scope in C?

Nothing physical happens. A typical implementation will allocate enough space in the program stack to store all variables at the deepest level of block nesting in the current function. This space is typically allocated in the stack in one shot at the function startup and released back at the function exit.


2 Answers

Looks like the new syntax for Uniform initialization in C++0x to me.

like image 52
reko_t Avatar answered Oct 08 '22 15:10

reko_t


This isn't returning a block. This constructs an object of type _Setbase, defined in the same header file as

struct _Setbase { int _M_base; };
like image 29
Fred Foo Avatar answered Oct 08 '22 13:10

Fred Foo