If statements

Discussion in 'C Programming' started by Sheldon, Jan 12, 2007.

  1. Sheldon

    Sheldon Guest

    Hi,

    I would like to know if there is a limit to how many conditions can be
    used in an if statement. For example:
    if ( a && b && c && d && e && f.....) {
    command
    }

    I am not suggesting ridiculous amounts like 20 but rather 4 or 5
    conditions?

    Is there a limit?

    /Sheldon
     
    Sheldon, Jan 12, 2007
    #1
    1. Advertising

  2. Sheldon said:

    > Hi,
    >
    > I would like to know if there is a limit to how many conditions can be
    > used in an if statement. For example:
    > if ( a && b && c && d && e && f.....) {
    > command
    > }
    >
    > I am not suggesting ridiculous amounts like 20 but rather 4 or 5
    > conditions?
    >
    > Is there a limit?


    As far as I can tell, the only applicable limit is the length of a logical
    source line! That's 509 in C90, and 4095 in C99.

    In other words, you won't hit any practical limits unless you're trying
    pretty hard.

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at the above domain, - www.
     
    Richard Heathfield, Jan 12, 2007
    #2
    1. Advertising

  3. Sheldon

    santosh Guest

    Richard Heathfield wrote:
    > Sheldon said:
    > > Hi,
    > >
    > > I would like to know if there is a limit to how many conditions can be
    > > used in an if statement. For example:
    > > if ( a && b && c && d && e && f.....) {
    > > command
    > > }

    <snip>
    > As far as I can tell, the only applicable limit is the length of a logical
    > source line! That's 509 in C90, and 4095 in C99.


    Which can be extended with the line continuation character, which is a
    backslash.
     
    santosh, Jan 12, 2007
    #3
  4. Sheldon

    Sheldon Guest

    santosh skrev:

    > Richard Heathfield wrote:
    > > Sheldon said:
    > > > Hi,
    > > >
    > > > I would like to know if there is a limit to how many conditions can be
    > > > used in an if statement. For example:
    > > > if ( a && b && c && d && e && f.....) {
    > > > command
    > > > }

    > <snip>
    > > As far as I can tell, the only applicable limit is the length of a logical
    > > source line! That's 509 in C90, and 4095 in C99.

    >
    > Which can be extended with the line continuation character, which is a
    > backslash.


    Thanks!!

    /S
     
    Sheldon, Jan 12, 2007
    #4
  5. santosh wrote:
    > Richard Heathfield wrote:
    > > Sheldon said:
    > > > Hi,
    > > >
    > > > I would like to know if there is a limit to how many conditions can be
    > > > used in an if statement. For example:
    > > > if ( a && b && c && d && e && f.....) {
    > > > command
    > > > }

    > <snip>
    > > As far as I can tell, the only applicable limit is the length of a logical
    > > source line! That's 509 in C90, and 4095 in C99.

    >
    > Which can be extended with the line continuation character, which is a
    > backslash.


    You don't even need that. There is no requirement that all conditions
    in an if statement appear on a single line. You can write

    if (a
    && b
    && c
    && d)
    {
    /* ... */
    }
     
    =?utf-8?B?SGFyYWxkIHZhbiBExLNr?=, Jan 12, 2007
    #5
  6. Sheldon

    Eric Sosman Guest

    santosh wrote:
    > Richard Heathfield wrote:
    >> Sheldon said:
    >>> Hi,
    >>>
    >>> I would like to know if there is a limit to how many conditions can be
    >>> used in an if statement. For example:
    >>> if ( a && b && c && d && e && f.....) {
    >>> command
    >>> }

    > <snip>
    >> As far as I can tell, the only applicable limit is the length of a logical
    >> source line! That's 509 in C90, and 4095 in C99.

    >
    > Which can be extended with the line continuation character, which is a
    > backslash.


    Nit-pick: Backslash-newline joins multiple *physical* source
    lines into a single *logical* source line, whose length may be
    subject to the limits Richard mentions. See section 5.1.1.2,
    paragraph 1, point 2.

    --
     
    Eric Sosman, Jan 12, 2007
    #6
  7. Sheldon

    santosh Guest

    Eric Sosman wrote:
    > santosh wrote:
    > > Richard Heathfield wrote:
    > >> Sheldon said:
    > >>> Hi,
    > >>>
    > >>> I would like to know if there is a limit to how many conditions can be
    > >>> used in an if statement. For example:
    > >>> if ( a && b && c && d && e && f.....) {
    > >>> command
    > >>> }

    > > <snip>
    > >> As far as I can tell, the only applicable limit is the length of a logical
    > >> source line! That's 509 in C90, and 4095 in C99.

    > >
    > > Which can be extended with the line continuation character, which is a
    > > backslash.

    >
    > Nit-pick: Backslash-newline joins multiple *physical* source
    > lines into a single *logical* source line, whose length may be
    > subject to the limits Richard mentions. See section 5.1.1.2,
    > paragraph 1, point 2.


    That's a major correction; my post is incorrect.
    Thanks.
     
    santosh, Jan 12, 2007
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. rajan

    generate statements

    rajan, Jul 3, 2003, in forum: VHDL
    Replies:
    1
    Views:
    8,489
    Egbert Molenkamp
    Jul 4, 2003
  2. Neil Zanella
    Replies:
    8
    Views:
    1,196
    mfmehdi
    Oct 20, 2006
  3. Harry George
    Replies:
    6
    Views:
    392
    Bart Nessux
    Feb 23, 2004
  4. Vince
    Replies:
    12
    Views:
    754
    Martin Gregorie
    Jan 21, 2008
  5. John Crichton
    Replies:
    6
    Views:
    267
    John Crichton
    Jul 12, 2010
Loading...

Share This Page