int main()
{
int var;
char string[50];
(var, string);
(0);
(0, 1, 2);
return 0;
} Reply ASAP
Thanks in advance
Govinda Attal.
int main()
{
int var;
char string[50];
(var, string);
(0);
(0, 1, 2);
return 0;
} Reply ASAP
Thanks in advance
Govinda Attal.
Brief, practical explanation and a few concrete checks.
The parenthesized lines in ’s snippet are expression statements: the compiler evaluates each expression and discards the resulting value. When an expression has no side effects, that evaluation does nothing observable at runtime, which is why the generated program looks empty in a disassembly. Other posters touched on this (, , , ); the important addition is that one of those expressions actually reads an uninitialized automatic variable — that is undefined behavior in C and should be treated as a bug even if the compiler produces no visible instructions.
Key points and quick fixes:
int i = 1, j = 2;
int result = (i *= 3, j + 4); /* i becomes 3; result gets 6 */ Bottom line: the code is syntactically valid and often compiles into essentially nothing, but it contains a real bug (use of an uninitialized local) and should be replaced with initialized variables or removed entirely.
Jump to Post— mostafadotnet 18Hi govinda.attal,
This means nothing.
Jump to Post— andor 25This code does compile and generates an exe file...When I went thru disassembly, I found nothing useful in it...There were no nops in it. First of all our basic coding principles say that it should give a compiler error... compilers like msvc, gcc simply pass without giving any error or …
Several no-ops? What is your question?
This code does compile and generates an exe file...When I went thru disassembly, I found nothing useful in it...There were no nops in it. First of all our basic coding principles say that it should give a compiler error... compilers like msvc, gcc simply pass without giving any error or warnings..
This code does compile and generates an exe file...When I went thru disassembly, I found nothing useful in it...There were no nops in it. First of all our basic coding principles say that it should give a compiler error... compilers like msvc, gcc simply pass without giving any error or warnings..
I compiled to assembly and peeked at it too. The compiler just optimizes the NOPs out, so you pretty much get stack allocation and stack deallocation and that's it.
Why would compiller give an error? That's a valid program.
This code does compile and generates an exe file...When I went thru disassembly, I found nothing useful in it...There were no nops in it. First of all our basic coding principles say that it should give a compiler error... compilers like msvc, gcc simply pass without giving any error or warnings..
<gcc simply pass without giving errors or warnings
Well there are warnings. Try to copile like this gcc var.c -o var -Wall <When I went thru disassembly, I found nothing useful in it
ofcourse that's exactly what warnings try to tell
var.c: In function `main':
var.c:6: warning: left-hand operand of comma expression has no effect
var.c:8: warning: left-hand operand of comma expression has no effect
var.c:8: warning: left-hand operand of comma expression has no effect
var.c:6: warning: statement with no effect
var.c:7: warning: statement with no effect
var.c:8: warning: statement with no effect We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.