Search code examples
pythonc++stringcomments

Can I use strings as comments in c++?


In Python, there are two types of comments.
The first using # (One-line comments)

# This is a comment
This_is_not()

The other using """/''' (Multi-line comments)

"""
This is a comment
"""
'''
Yet another comment
'''
NOT_a_comment()



In C++, there are two types of comments.
The first using // (One-line comments)

// This is a comment
This_is_not_a_comment();

The other using /*/*/ (Multi-line comments)

/*
This is a comment
*/
This_is____well_you_get_the_idea();



My question is,
Can I use strings as comments in C++?
If I do, gcc gives me a warning.

warning: statement has no effect [-Wunused-value]
    "This is a comment";
    ^~~~~~~~~~~~~~~~~~~

But if I just ignore the warning (With -Wno-unused-value possibly) It will be okay, right?


Solution

  • Comments are skipped by the compilers during compilation whereas values and their assignments aren't. It'll be better to avoid using unused string values because nevertheless they're unused, they're at least included in compilation. OTOH, comments are ignored.