Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4560410
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T17:55:35+00:00 2026-05-21T17:55:35+00:00

I caught very strange bug(?) which took me almost whole day to find it

  • 0

I caught very strange bug(?) which took me almost whole day to find it in real application. In the code there was a elseif block which was commented out and it led to execution of code which (as I thought) could not ever be executed.

I simplified the testcase which reproduces this odd tcl behavior.

proc funnyProc {value} {
  if {$value} {
    return "TRUE"
#  } elseif {[puts "COMMENT :)"] == ""} {
#    return "COMMENT"
  } else {
    return "FALSE"
  }
  return "IT'S IMPOSSIBLE!!!"
}

puts [funnyProc false]

What do you think this program will output?

  1. The puts in the comment line is executed. It’s impossible from any programming language POV.
  2. The line after the block if {...} {return} else {return} is executed as well. It’s impossible from true/false logic.

I know that tcl-comment behaves like a command with the name # and consumes all arguments until EOL. And tcl parser do not like unbalanced curly brackets in comments. But this case is out of my understanding.

Maybe I missed something important? How to correctly comment out such elseif blocks, so do not have these weird side-effects?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T17:55:36+00:00Added an answer on May 21, 2026 at 5:55 pm

    This is because # is only a comment when Tcl is looking for the start of a command, and the first time it sees it above (when parsing the if), it’s looking for a } in order to close the earlier {. This is a consequence of the Tcl parsing rules; if is just a command, not a special construct.

    The effect that Ernest noted is because it increases the nesting level of the braces on that line, which makes it part of the argument that runs from the end of the if {$value} { line to the start of the } else { line. Then the # becomes special when if evaluates the script. (Well, except it’s all bytecode compiled, but that’s an implementation detail: the observed semantics are the same except for some really nasty edge cases.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello Friends i have the following query which defeat the very purpose. A day
I recently ran into a very sneaky bug, in which I forget to dereference
I am trying to setup a few fixes in some code that have caught
I have class which is seralized and does convert a very large amount of
I'm currently in the research phase for a (very) small database application. It's for
There was a very interesting discussion on LosTechies regarding AutoMapper(an argument for/against 2-way mapping).
Is there an way to disable WPF's very annoying exception wrapping when debugging? An
The following code is pretty self-explanatory and my question is very simple : Why
I was testing a c++11 compiler on my source code and it caught an
Recently scalaz caught my eye. It looks very interesting, but I have not found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.