Pointless?

closed account (zb0S216C)
Today, I was writing a piece of code when I found out that if I typed a variable's identifier( after defining it ) without doing anything with it, is allowed. Below is a code segment showing what I mean if you don't already.

1
2
3
4
5
6
7
8
int main( )
{
    int Variable( 0 );

    Variable;    // This is what I'm referring to.

    return 0;
}

Can this even be used? Any thoughts on it?

Thanks.
Last edited on
Any statement my stand for itself, just like you can call a function returning a value without actually using the return value. This could be used with cases in which retrieving a value has desirable side effects, but other than that it's just language stuff, because EXPRESSION-SEMICOLON is valid syntax. Most compilers would probably give you a warning that you aren't actually doing anything there.
closed account (zb0S216C)
I get what you're saying, Hanst. Basically, Variable; is a hanging value? Also, GNU GCC doesn't generate an warning regarding Variable.
Yes, it does.
$ g++ -Wall -c var.cpp
var.cpp: In function ‘int main(int, char**)’:
var.cpp:5: warning: statement has no effect

closed account (zb0S216C)
That's strange, Ne555. -Wall has been enabled for a long time and it never gave me the warning. Is it possible that the compiler is OOD( out-of-date )?
Last edited on
Possible. What version are you using?
closed account (zb0S216C)
I have no idea. I've never came across the version and personally, I have no idea how to find it.
closed account (1yR4jE8b)
g++ --version
closed account (zb0S216C)
This is the problem, I see people using commands such as g++ --version, but, how do I actually use them within Code::Blocks?
Just open your terminal of choice and do the commands from there?
closed account (zb0S216C)
Thank you, Hanst. I was able to locate the version: 4.4.1. I guess it's OOD.
Topic archived. No new replies allowed.