Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What would 'std:;' do in c++?

Tags:

c++

std

colon

I was recently modifying some code, and found a pre-existing bug on one line within a function:

std:;string x = y; 

This code still compiles and has been working as expected.

The string definition works because this file is using namespace std;, so the std:: was unnecessary in the first place.

The question is, why is std:; compiling and what, if anything, is it doing?

like image 776
user1410910 Avatar asked Oct 09 '12 19:10

user1410910


People also ask

What does std :: mean in C?

Basically STD is short for standard (in c++ only. If your doctor mentions it it's definitely not standard) and it's just a set of data types and commands prepackaged with the language. The reason you have to include them is because they're actually .c and .h files tucked into the compiler.

What is the point of std :: function?

Class template std::function is a general-purpose polymorphic function wrapper. Instances of std::function can store, copy, and invoke any Callable target -- functions, lambda expressions, bind expressions, or other function objects, as well as pointers to member functions and pointers to data members.

Can C use STD?

All C++ standard library names, including the C library names, if you include them, are defined in the namespace std . This means that you must qualify all the library names using one of the following methods: Specify the standard namespace, for example: std::printf("example\n");

Does using namespace std affect performance?

It doesn't affect the runtime performance at all.


1 Answers

std: its a label, usable as a target for goto.

As pointed by @Adam Rosenfield in a comment, it is a legal label name.

C++03 §6.1/1:

Labels have their own name space and do not interfere with other identifiers.

like image 135
K-ballo Avatar answered Sep 19 '22 08:09

K-ballo