int main()
{
       int var;
       char string[50];
       
       (var, string);
       (0);
       (0, 1, 2);
 
       return 0;
}

Reply ASAP
Thanks in advance
Govinda Attal.

Dani AI

Generated

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:

  • Comma inside an expression is the comma operator: the left operand is evaluated first, then the right; the whole expression yields the right operand’s value. This is different from commas used as separators (e.g., in declarations or function arguments).
  • Reading an automatic variable that was never initialized is undefined behavior. Initialize locals before using them.
  • If you want to use the comma operator for sequencing side effects, do so where the side effects matter (assignment, function calls, etc.). Example:
int i = 1, j = 2;
int result = (i *= 3, j + 4);  /* i becomes 3; result gets 6 */
  • Common diagnostic steps:
    • Enable warnings (GCC: -Wall -Wextra and additional checks like -Wuninitialized) and use optimization when necessary to allow some analyses to run.
    • Inspect unoptimized assembly (-O0 -S) or disassemble the object to compare before/after optimizations.
    • To force a visible memory access for inspection, initialize variables or declare them volatile (for debugging only).

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.

Recommended Answers

All 6 Replies

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.