#define constants

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ioannis Vranos

    #define constants

    I think I read somewhere that #define constants in the style


    #define SOMETHING 6


    are evaluated to long or unsigned long, depending on the situation and
    not int.
  • Ioannis Vranos

    #2
    Re: #define constants

    Ioannis Vranos wrote:
    I think I read somewhere that #define constants in the style
    >
    >
    #define SOMETHING 6
    >
    >
    are evaluated to long or unsigned long, depending on the situation and
    not int.

    .... Is that true?

    Comment

    • Victor Bazarov

      #3
      Re: #define constants

      Ioannis Vranos wrote:
      Ioannis Vranos wrote:
      >I think I read somewhere that #define constants in the style
      >>
      >>
      >#define SOMETHING 6
      >>
      >>
      >are evaluated to long or unsigned long, depending on the situation
      >and not int.
      >
      >
      ... Is that true?
      I don't know whether it's true that you read that nonsense somewhere
      or whether you dreamed it. I know that an integral literal has the
      type 'int' if it fits in it, and if it doesn't, it has type long int,
      unless overridden by a suffix (absent in your example). This all is
      defined in [lex.icon]/2.

      V
      --
      Please remove capital 'A's when replying by e-mail
      I do not respond to top-posted replies, please don't ask


      Comment

      • Ioannis Vranos

        #4
        Re: #define constants

        Victor Bazarov wrote:
        Ioannis Vranos wrote:
        >Ioannis Vranos wrote:
        >>I think I read somewhere that #define constants in the style
        >>>
        >>>
        >>#define SOMETHING 6
        >>>
        >>>
        >>are evaluated to long or unsigned long, depending on the situation
        >>and not int.
        >>
        >... Is that true?
        >
        I don't know whether it's true that you read that nonsense somewhere
        or whether you dreamed it. I know that an integral literal has the
        type 'int' if it fits in it, and if it doesn't, it has type long int,
        unless overridden by a suffix (absent in your example). This all is
        defined in [lex.icon]/2.

        My mistake. It is about the "identifier " of the macro expressions

        defined identifier

        and

        defined ( identifier)


        Errata for K&R2 page 232 (from



        232(§A12.5): The result of the defined operator is not replaced
        literally by 0L or 1L, nor are undefined names literally by 0L, but just
        by plain 0 or 1. However, the constant expression is nevertheless
        evaluated as if these and other constants appearing have long or
        unsigned long type.

        Comment

        • Ioannis Vranos

          #5
          Re: #define constants

          Ioannis Vranos wrote:
          Victor Bazarov wrote:
          >Ioannis Vranos wrote:
          >>Ioannis Vranos wrote:
          >>>I think I read somewhere that #define constants in the style
          >>>>
          >>>>
          >>>#define SOMETHING 6
          >>>>
          >>>>
          >>>are evaluated to long or unsigned long, depending on the situation
          >>>and not int.
          >>... Is that true?
          >I don't know whether it's true that you read that nonsense somewhere
          >or whether you dreamed it. I know that an integral literal has the
          >type 'int' if it fits in it, and if it doesn't, it has type long int,
          >unless overridden by a suffix (absent in your example). This all is
          >defined in [lex.icon]/2.
          >
          >
          My mistake. It is about the "identifier " of the macro expressions
          >
          defined identifier
          >
          and
          >
          defined ( identifier)
          >
          >
          Errata for K&R2 page 232 (from

          >
          >
          232(§A12.5): The result of the defined operator is not replaced
          literally by 0L or 1L, nor are undefined names literally by 0L, but just
          by plain 0 or 1. However, the constant expression is nevertheless
          evaluated as if these and other constants appearing have long or
          unsigned long type.

          The fact that the "identifier " in a "defined" preprocessor statement is
          evaluated as long or unsigned long, doesn't it imply that this
          identifier which was defined with #define" preprocessor statement is
          evaluated as long or unsigned long everywhere?

          Comment

          • Ioannis Vranos

            #6
            Re: #define constants

            Ioannis Vranos wrote:
            Ioannis Vranos wrote:
            >Victor Bazarov wrote:
            >>Ioannis Vranos wrote:
            >>>Ioannis Vranos wrote:
            >>>>I think I read somewhere that #define constants in the style
            >>>>>
            >>>>>
            >>>>#define SOMETHING 6
            >>>>>
            >>>>>
            >>>>are evaluated to long or unsigned long, depending on the situation
            >>>>and not int.
            >>>... Is that true?
            >>I don't know whether it's true that you read that nonsense somewhere
            >>or whether you dreamed it. I know that an integral literal has the
            >>type 'int' if it fits in it, and if it doesn't, it has type long int,
            >>unless overridden by a suffix (absent in your example). This all is
            >>defined in [lex.icon]/2.
            >>
            >My mistake. It is about the "identifier " of the macro expressions
            >>
            >defined identifier
            >>
            >and
            >>
            >defined ( identifier)
            >>
            >>
            >Errata for K&R2 page 232 (from
            >http://www-db-out.research.bell-labs...ediffs.html):\
            >>
            >>
            >232(§A12.5): The result of the defined operator is not replaced
            >literally by 0L or 1L, nor are undefined names literally by 0L, but just
            >by plain 0 or 1. However, the constant expression is nevertheless
            >evaluated as if these and other constants appearing have long or
            >unsigned long type.
            >
            >
            The fact that the "identifier " in a "defined" preprocessor statement is
            evaluated as long or unsigned long, doesn't it imply that this
            identifier which was defined with #define" preprocessor statement is
            evaluated as long or unsigned long everywhere?

            My mistake again, the _result_ of the defined operator is replaced by 0
            or 1 which are evaluated as 0L and 1L. Strange stuff.

            Comment

            • Ioannis Vranos

              #7
              Re: #define constants

              OK, lets get it from the start again:


              Errata for K&R2 page 232 (from



              232(§A12.5): The result of the defined operator is not replaced
              literally by 0L or 1L, nor are undefined names literally by 0L, but just
              by plain 0 or 1. However, the constant expression is nevertheless
              evaluated as if these and *other constants* appearing have long or
              unsigned long type.


              When it mentions "these and other constants", what are the other
              constants implied?

              Comment

              • Ron Natalie

                #8
                Re: #define constants

                Ioannis Vranos wrote:
                I think I read somewhere that #define constants in the style
                >
                >
                #define SOMETHING 6
                >
                >
                are evaluated to long or unsigned long, depending on the situation and
                not int.
                Nope. Not true. #define has little to do with (unless you are
                throwing in some token pasting operators), an decimal integer literal
                has type the smaller of int or long int that can hold it.

                Other constraints on the language make 6 HAVE to be of type int.

                There's no way a decimal literal ever has type unsigned.

                Comment

                Working...