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 2470 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)
Parents
  • 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
  • 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
Reply
  • 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
Children
  • amgalbu
    0 amgalbu over 9 years ago in reply to Former Member

    Noto dure you can replace a C keyword with a define...

    • 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 amgalbu

    This is what I was suggesting:

     

    #define TRUE 1

     

    if(TRUE) {

         whatever

    }

     

    This is one obvious and historical way of making simple

    C if-statements more readable.

    There are many ways to use #define statements in making C

    quite readable to organizational standards.

    That is why #define is called a macro statement,

    with historical roots in various assembly languages.

    • 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 amgalbu

    Part 2.

     

    By a new preprocessor, I meant to either (1) change the existing C preprocessor (cpp, which is open source) or (2) write a new one to front-end `cpp`.  I doubt if amending cpp or creating a new preprocessor is worth it.

     

    Akshay still has not articulated the circumstance where "if()" is generated or derived from something else.  Clearly, one would not create meaningless code like that by hand.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify 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