A command that does nothing in c++?

Does anyone knows a command that does nothing in c++?
I mean - a command that the compiler reads and ignores, for example, if I want to execute the following program:
let's call this command 'blank'

void main(){
int a=1,b=2;
int temp=a;
b>a ? temp=b:blank;
}

Note: I know I can simply do temp=temp or something, but that's not what I'm looking for...

Thanks!
closed account (Dy7SLyTq)
a) why do you want to do it that way?
b) not that i know of, because it would be pointless
c) just do a null type thing
never mind, solved
Last edited on
Heh, command that does nothing.

for (;;) break;

Command that does nothing forever.

for (;;) ;
Maybe boost::optional? http://www.boost.org/doc/libs/1_51_0/libs/optional/doc/html/index.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <boost/optional.hpp>
using boost::optional;

optional<int> f(int a, int b)
{
	if (a < b)
		return optional<int>(a);
	else
		return optional<int>();//uninitialized
}
int main() 
{
	int a = 5, b = 10;
	optional<int> c = f(a, b);

	if (c.is_initialized())
		std::cout << *c << std::endl;
	else
		std::cout << "c is uninitialized" << std::endl;
}
Note: I know I can simply do temp=temp or something, but that's not what I'm looking for...


OR you could just use if

1
2
3
int a=1, b=2, temp=a;
if(b > a)
    temp = b;


Just to answer exactly what you're asking for I'd probably do something like Sleep(1);, but I imagine if there was anything that truly did do absolutely nothing (like a + b but without assigning it to anything) that the the compiler would recognise this and just remove it from the executable file.
Topic archived. No new replies allowed.