Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C macro Stringizing operator not recognized #157

Open
GoogleCodeExporter opened this issue Jan 14, 2016 · 3 comments
Open

C macro Stringizing operator not recognized #157

GoogleCodeExporter opened this issue Jan 14, 2016 · 3 comments

Comments

@GoogleCodeExporter
Copy link

When using a C macro with stringized variables, all the code after the # will 
appear greyed-out as a preprocessor directive:

<pre class="lang-c prettyprint-override"><code>#define MIN(a, b) (a &lt; b ? a 
: b)
#define LARGEST_INT_TYPE unsigned long long
#define testimax(TEST_TYPE) {\
  LARGEST_INT_TYPE in, out;\
  size_t pow, limit;\
  TEST_TYPE t;\
  in = 1; out = 2; pow = 0;\
  limit = MIN(sizeof(TEST_TYPE)*8,\
    sizeof(LARGEST_INT_TYPE)*8);\
  while (pow &lt; limit &amp;&amp; out == in + 1) {\
    in = in &lt;&lt; 1;\
    t = (TEST_TYPE) in + 1;\
    out = t;\
    ++pow;\
  }\
  if (pow == limit)\
    puts( #TEST_TYPE " seems integral");\
  else printf (#TEST_TYPE\
    " conversion imprecise for 2^%d+1:\n"\
    "   in: %llu\n  out: %llu\n\n", pow, in + 1, out);\
}

int main(void)
{
    testimax(float);
    testimax(double);
}
</code></pre> 

for `puts( #TEST_TYPE " seems integral");\`, the string after `#TEST_TYPE` 
should be syntax-highlighted as a string. 

Don't know the version: this is from 
http://stackoverflow.com/questions/6060406/using-floats-or-doubles-instead-of-in
ts/6060451#6060451 on Google Chrome 13.0.782.1 dev-m Windows.

Original issue reported on code.google.com by [email protected] on 3 Jun 2011 at 6:34

@GoogleCodeExporter
Copy link
Author

How does the C preprocessor lexer distinguish a '#' that starts a preprocessor 
directive from one that does not?

Original comment by [email protected] on 3 Jun 2011 at 11:42

@GoogleCodeExporter
Copy link
Author

Just ran into this as well.

I don't know how it works in C, but in C++ `#` is a preprocessor directive 
exactly when it is either the first nonwhitespace character in the source file 
or is preceded by whitespace containing a newline. 

Reference: C++ working draft N3242, "Preprocessing Directives" 
[http://www.open-std.org/jtc1/sc22/wg21/] 

Original comment by [email protected] on 7 Apr 2012 at 11:37

@GoogleCodeExporter
Copy link
Author

Related to this issue, I don't know why #include/define/etc are marked as 
comments. I think that C-like languages should have hashComments=false. You can 
fix this issue modifying prettify.js source code. Search for:

  registerLangHandler(sourceDecorator({
          'keywords': CPP_KEYWORDS,
          'hashComments': false,   // This is true in the official release
          'cStyleComments': true,
          'types': C_TYPES
        }), ['c', 'cc', 'cpp', 'cxx', 'cyc', 'm']);

I've attached a patch to fix this issue.

Original comment by davidcapello on 13 Dec 2013 at 7:42

Attachments:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant