Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 238 Vote(s) - 3.7 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What is the # for when formatting using %s

#1
I came across this example of an assertion and was wondering what the `#` is for:

#define ASSERT( x ) if ( !( x ) ) { \
int *p = NULL; \
DBGPRINTF("Assert failed: [%s]\r\n Halting.", #x); \
*p=1; \
}

Reply

#2
`#x` is the stringification directive

`#define Stringify(x) #x`

means `Stringify(abc)` will be substituted with `"abc"`

as in

#define initVarWithItsOwnName(x) const char* p = #x

int main()
{
initVarWithItsOwnName(Var);
std::cout << Var; //will print Var
}
Reply

#3
It is the "stringize" preprocessing operator.

It takes the tokens passed as the argument to the macro parameter `x` and turns them into a string literal.

#define ASSERT(x) #x

ASSERT(a b c d)
// is replaced by
"a b c d"
Reply

#4
`#` is the preprocessor's ["stringizing" operator][1]. It turns macro parameters into string literals. If you called `ASSERT(foo >= 32)` the `#x` is expanded to `"foo >= 32"` during evaluation of the macro.

[1]:

[To see links please register here]

Reply

#5
It's a preprocessor feature called [stringification][1]. It

> replaces [the macro parameter] with the literal text of the actual argument, converted to a string constant.


[1]:

[To see links please register here]

Reply

#6
It's the stringizing operator.

[To see links please register here]

Reply

#7
What you see is called *stringification*. It allows you to convert an argument of a macro into a string literal. You can read more about it here

[To see links please register here]

.
Reply

#8
`#` is the stringizing operator defined in Section 6.10.3.2 (C99) and in Section 16.3.2. (C++03)

It converts macro parameters to string literals without expanding the parameter definition.

>If the replacement that results is not a valid character string literal, the
behavior is **undefined**. The order of evaluation of # operator is **unspecified**.

For instance, syntactically, occurrences of the backslash character in string literals are limited to escape sequences.

In the following example:

1 #define mkstr(x) # x
2 char *p = mkstr(a \ b);
/* "a \ b" violates the syntax of string literals */

the result of the `#` operator need not be `"a \ b"`.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through