Skip to content

Instantly share code, notes, and snippets.

@sanpingz
Last active December 17, 2015 16:08
Show Gist options
  • Save sanpingz/5636153 to your computer and use it in GitHub Desktop.
Save sanpingz/5636153 to your computer and use it in GitHub Desktop.
C++ comments
#include <stdio.h>
int main(){
/**** 1. backslash-newline ****/
int a = 1;
//some comments \
a++;
printf("%d\n", a);
int b = 1;
//some comments ??/
b++;
printf("%d\n", b);
/\
/ some comments
/\
*
some comments
*/
/**** 2. trigraph sequences ****/
/*
----------------------------------------------------------------------------
| trigraph | replacement | trigraph | replacement | trigraph | replacement |
----------------------------------------------------------------------------
| ??= | # | ??( | [ | ??< | { |
| ??/ | \ | ??) | ] | ??> | } |
| ??’ | ˆ | ??! | | | ??- | ˜ |
----------------------------------------------------------------------------
*/
printf("seems to work (but is it right??)"); // seems to work (but is it right]
/*
warning: trigraph ??/ ignored, use -trigraphs to enable [-Wtrigraphs]
g++ demo.cpp -o demo -trigraphs
*/
/**** 3. nested comments ****/
//! /*something /* something else */ */
int ans = /*/*/0*/**/1;
printf("\n%d\n", ans);
#if 0
commments1
#if 0
comments2
#endif
commments3
#endif
/**** 4. bad comments ****/
/*
comments
* /
code = 1; /* comments !*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment