element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Code Exchange
  • Technologies
  • More
Code Exchange
Forum Redundant parathensis in C
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Code Exchange to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Suggested Answer
  • Replies 26 replies
  • Answers 4 answers
  • Subscribers 52 subscribers
  • Views 2462 views
  • Users 0 members are here
  • Code Exchange
  • redundant
  • conditional tricky writing style
  • if else construct
  • paranthesis
Related

Redundant parathensis in C

dr.akshay_1980@yahoo.com
dr.akshay_1980@yahoo.com over 9 years ago

Hi,

Out of curiosity and experimenting with ANSI C constructs ,I would like to know any means by which we can ignore the empty braces for the conditional statements in C programming??? Does C allow us to do this.

 

Refer below the sample C code for discussion

 

 

int main()

{

     if()             /// there should no error while writing this, empty parathensis..

{

     printf("your if  is without parameters...");

}

else

{

    printf("if block ignored....");

}

return 0;

}

 

 

How to implement the above code in C successfully without any errors(compile time/Run time)????? By any means I want to implement above style.

 

 

Thanks in advance....

  • Sign in to reply
  • Cancel

Top Replies

  • shabaz
    shabaz over 9 years ago in reply to clem57 +2
    It looks like another interview/college homework type question (they do ask odd questions sometimes). Much like this one: If-Else construct in C language-hello world As you say, nothing for any real practical…
  • amgalbu
    amgalbu over 9 years ago +1 suggested
    According to c grammar, you need to type a boolean expression. So there is no way to create an if without condition
  • amgalbu
    amgalbu over 9 years ago in reply to D_Hersey +1
    @akshay dharma is asking if it is possibile to uae empty braces after a if keyword. That's noto possibile imho. Btw true and false are c++ keywords, and are not allowed in ANSI c (aka c90)
  • dr.akshay_1980@yahoo.com
    0 dr.akshay_1980@yahoo.com over 9 years ago in reply to clem57

    Hi Clem, I do agree with you, but after all C logic can be bypassed as we people have developed the C. In this case my intention is that you people should come out with OUT OF BOX solution for this , being an embedded developer I generally come across situations where I have to convert the C++/JAVA code into C(for lower end systems that don't support OOPS), I was just fiddling with if else construct....

     

    The approach from my end is to befool the compiler anyhow and lets bypass the conditional check for if using pragma directives or assert macros... i was looking ahead in this direction...

     

    Can we come out for its solution...???

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • dr.akshay_1980@yahoo.com
    0 dr.akshay_1980@yahoo.com over 9 years ago

    Hi all, I do agree with you people and very much conscious about C language principles, but after all C logic can be bypassed as we people have only developed the C. In this case my intention is that you people should come out with OUT OF BOX solution for this , being an embedded developer I generally come across situations where I have to convert the C++/JAVA code into C(for lower end systems that don't support OOPS), I was just fiddling with if else construct....

     

    The approach from my end is to befool the compiler anyhow and lets bypass the conditional check for if using pragma directives or assert macros... I was looking ahead in this direction...

     

    Can we come out for its solution...???

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • clem57
    0 clem57 over 9 years ago

    Your style fits poorly and is ill conceived. A style needs universal suffrage.

    Clem

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • amgalbu
    0 amgalbu over 9 years ago in reply to dr.akshay_1980@yahoo.com

    Can you point out a practical case?

    Empty braces could be always evaluated ad either true or false (depending on the semantica you want to adopt) so you can simply remove the if()

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 9 years ago in reply to dr.akshay_1980@yahoo.com

    A nil boolean expression has no cognitive meaning and is therefore correctly diagnosed as missing by `gcc`.  I suggest that you either code if(1) or #define TRUE 1 and use if(TRUE).

     

    Don't fight something that isn't going to change because there is no point to do so.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • D_Hersey
    0 D_Hersey over 9 years ago in reply to Former Member

    https://en.wikipedia.org/wiki/Three-valued_logic

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • amgalbu
    0 amgalbu over 9 years ago in reply to D_Hersey

    That's really interesting. Can't think of a practical usage but an interesting answer to explain the meanung of "if ()"

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 9 years ago in reply to D_Hersey

    Don, I do not know why you were pointing out 3-valued logic.  In any case, the C if statement is clearly based on 2-valued logic.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 9 years ago in reply to dr.akshay_1980@yahoo.com

    "C logic can be bypassed as we people have only developed the C"

     

    If you want to "bypass" C syntax requirements, then you are talking about a new language.

    More practically, you could write your own preprocessor and expand if() statements any way you like.

     

    How did you wind up with an if() in the first place?  Could you supply a practical example?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • D_Hersey
    0 D_Hersey over 9 years ago

    My only motivation in bringing up three-valued logic is a vain attempt to bring something interesting to this thread.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
<>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube