Loading ...
Sorry, an error occurred while loading the content.

Re: C syntax minor error: unsigned/signed not highlighted for unnamed bit fields if without int

Expand Messages
  • Bram Moolenaar
    ... There is a syntax item to avoid bitfield specifications to be recognized as jump labels. It avoids other highlighting in that spot. Please try this patch
    Message 1 of 1 , May 1, 2006
    • 0 Attachment
      slimzhao wrote:

      > given the following legal C syntax:
      > struct T
      > {
      > unsigned a : 1;
      > unsigned b : 1;
      > unsigned int : 0;
      > unsigned c : 1;
      > unsigned d : 1;
      > unsigned int : 0;
      > signed : 1; //The signed will not be highlighted as keyword
      > unsigned : 1; //The unsigned will not be highlighted as keyword
      > signed e : 1;
      > };
      >
      > But in the case of a normal declaration:
      > int main()
      > {
      > unsigned a;
      > return 0;
      > }
      > unsigned is highlighted correctly.
      >
      > I'm re-reading the classic <<The C programming Language>> and find out
      > that:
      > (1)int can be absence in "unsigned int" and "signed int"
      > (2)0-width bit fields is permitted, which means that the next member will
      > be aligned at word boundary.
      > (3)A unnamed bit-field is allowed, acting as a placeholder.

      There is a syntax item to avoid bitfield specifications to be recognized
      as jump labels. It avoids other highlighting in that spot. Please try
      this patch and verify that there are no undesired side effects.

      --- runtime/syntax/c.vim 24 Apr 2006 19:26:38 -0000 1.7
      +++ runtime/syntax/c.vim 1 May 2006 08:37:32 -0000
      @@ -289,8 +289,8 @@
      syn match cUserLabel display "\I\i*" contained

      " Avoid recognizing most bitfields as labels
      -syn match cBitField display "^\s*\I\i*\s*:\s*[1-9]"me=e-1
      -syn match cBitField display ";\s*\I\i*\s*:\s*[1-9]"me=e-1
      +syn match cBitField display "^\s*\I\i*\s*:\s*[1-9]"me=e-1 contains=cType
      +syn match cBitField display ";\s*\I\i*\s*:\s*[1-9]"me=e-1 contains=cType

      if exists("c_minlines")
      let b:c_minlines = c_minlines

      --
      SUPERIMPOSE "England AD 787". After a few more seconds we hear hoofbeats in
      the distance. They come slowly closer. Then out of the mist comes KING
      ARTHUR followed by a SERVANT who is banging two half coconuts together.
      "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

      /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
      /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
      \\\ download, build and distribute -- http://www.A-A-P.org ///
      \\\ help me help AIDS victims -- http://ICCF-Holland.org ///
    Your message has been successfully submitted and would be delivered to recipients shortly.