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 8082571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:09:31+00:00 2026-06-05T17:09:31+00:00

I am wondering if a conditional operator could actually prevent other unrelated code from

  • 0

I am wondering if a conditional operator could actually prevent other unrelated code from working. For example below:

typedef char WCHAR_T;
#define STRLEN(x) strlen(x)
if (argc > 2)
{
    WCHAR *pFileName = argv[1];
    basic_string <WCHAR> strFileName(pFileName, STRLEN(pFileName));
}

In the code above, pFileName, argv[1] and strFileName have nothing to do with the comparison argc > 2. Assuming that the command line arguments are perfectly fine. However, this code would not work with that comparison. Also, even if I change the code to the following format:

typedef char WCHAR_T;
#define STRLEN(x) strlen(x)

{
    WCHAR *pFileName = argv[1];
    basic_string <WCHAR> strFileName(pFileName, STRLEN(pFileName));
}

Still doesn’t work.
EDIT: By “doesn’t work”, I mean compiler gives error message such as “strFileName” was not declared, which means this declaration didn’t run at all.

I have no idea why the curly braces would have such big impact at the code. When I get rid of the curly braces, the code works like magic…Could anyone explain this please? Thanks.

  • 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-06-05T17:09:32+00:00Added an answer on June 5, 2026 at 5:09 pm

    i guess you’re try to use the variable strFileName from somewhere outside the braces, which is not possible.

    the { and } braces define a block and variables declared inside are only existent inside this block.
    a workaround would be to declare strFileName outside of the block and assign it’s value from inside

    typedef char WCHAR_T;
    #define STRLEN(x) strlen(x)
    
    basic_string <WCHAR> strFileName;
    
    if (argc > 2)
    {
        WCHAR *pFileName = argv[1];
        strFileName.assign(pFileName, STRLEN(pFileName));
    }
    
    std::cout << strFileName << std::endl; // should work now
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using ternary operator for short conditional variable definition. I was wondering when the
Possible Duplicate: Type result with conditional operator in C# I was just working on
I'm wondering why there is an inconsistency with the code below. I would expect
I'm just wondering if it's possible to comment out IE conditional comments themselves (for
Wondering if there is any way to get the lambda expressions that result from
Wondering if I could get some advice and direction on this following requirement: Need
I was wondering if there was a ternary operator (condition ? true-value : false-value)
I was just wondering if there is an XOR logical operator in C (something
Just wondering if there is a way to do a conditional callback in Rails.
I just saw this block of code on the Wikipedia article on conditional operators:

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.