string-literals

Difference between string literal and constexpr array of char

天大地大妈咪最大 提交于 2019-11-29 13:15:51
I have been wondering if there is any difference between what is being pointed by ptrToArray and ptrToLiteral in the following example: constexpr char constExprArray[] = "hello"; const char* ptrToArray = constExprArray; const char* ptrToLiteral = "hello"; Is my understanding that constExprArray and the two "hello" literals are all compile time constant lvalues correct? If so, is there any difference in how they are stored in the executable file, or is it purely compiler implementation or platform specific? Are they treated differently at runtime behind the scenes? Anything else to know about?

Difference between N'String' vs U'String' literals in Oracle

扶醉桌前 提交于 2019-11-29 11:49:23
问题 What is the meaning and difference between these queries? SELECT U'String' FROM dual; and SELECT N'String' FROM dual; 回答1: In this answer i will try to provide informations from official resources (1) The N'' text Literal N'' is used to convert a string to NCHAR or NVARCHAR2 datatype According to this Oracle documentation Oracle - Literals The syntax of text literals is as follows: where N or n specifies the literal using the national character set ( NCHAR or NVARCHAR2 data). Also in this

Same strings in array have same memory address

梦想的初衷 提交于 2019-11-29 11:34:49
Why do same strings in a char* array have the same address? Is this because of compiler optimization? Example: #include <stdio.h> #include <stdlib.h> #include <string.h> #define ARR_SIZE 7 int main(int argc, char** argv) { size_t i = 0, j = 0; char * myArr[ARR_SIZE] = { "This is the first string", "This is the second string", "This is Engie", "This is the third string", "This is Engie", "This is the fifth string", "This is Engie" }; for (i = 0; i < ARR_SIZE; ++i){ for (j = i + 1; j < ARR_SIZE; ++j){ if (memcmp((myArr + i), (myArr + j), sizeof(char*)) == 0){ fprintf(stdout, "%p, %p\n", *(myArr

Is there a way to pull in a text resource into a raw string literal using the pre-processor?

前提是你 提交于 2019-11-29 11:07:58
I've just noticed that an answer I have given for this question actually doesn't work: Regardless of using CMake or not, the following should work with the current standard: std::string resource = R"( #include "text.txt" )"; I thought that the pre-processor would recognize the #include "text.txt" statement in first place and expand the text. But that's obviously not the case, the result for std::cout << resource << std::endl; is #include "text.txt" I tried to use some macro to let the #include statement be expanded within, but it doesn't work either: #include <string> #include <iostream>

Avoid warning in wrapper around printf

余生颓废 提交于 2019-11-29 10:46:34
I have an error reporting functionality in my little C library I'm writing. I want to provide an errorf function in addition to the plain error function to allow embedding information in error messages easily. /* * Prints a formatted error message. Use it as you would use 'printf'. See the * 'sio_error' function. */ void sio_errorf(const char *format, ...) { // Print the error prefix if (g_input == STDIN) fputs("error: ", stderr); else fprintf(stderr, "%s: ", g_progname); // Pass on the varargs on to 'vfprintf'. va_list arglist; va_start(arglist, format); // This may produce the following

What is the result of decltype(“Hello”)?

纵饮孤独 提交于 2019-11-29 10:41:19
问题 I'm getting unexpected results from all compilers on which I tried the following (GCC 4.7.2, GCC 4.8.0 beta, ICC 13.0.1, Clang 3.2, VC10): #include <type_traits> int main() { // This will fire static_assert( std::is_same<decltype("Hello"), char const[6]>::value, "Error!" ); } I would have expected the compile-time assertion above not to fire, but it does. After all, this one does not (as expected): #include <type_traits> int main() { char const hello[6] = "Hello"; // This will not fire static

MySQL unicode literals

杀马特。学长 韩版系。学妹 提交于 2019-11-29 08:04:41
问题 I want to insert a record into MySQL that has a non-ASCII Unicode character, but I'm on a terminal that doesn't let me easily type non-ASCII characters. How do I escape a Unicode literal in MySQL's SQL syntax? 回答1: See: http://bugs.mysql.com/bug.php?id=10199 (Bug #10199: "Allow Unicode escape sequence for string literals.") This request has been "Open" since 2005. More details in Worklog Task #3529: Unicode Escape Sequences. From https://web.archive.org/web/20091117221116/http://eng.kaching

Properly match a Java string literal [duplicate]

拈花ヽ惹草 提交于 2019-11-29 06:47:07
This question already has an answer here: Regex to replace all string literals in a Java file 4 answers I am looking for a Regular expression to match string literals in Java source code. Is it possible? private String Foo = "A potato"; private String Bar = "A \"car\""; My intent is to replace all strings within another string with something else. Using: String A = "I went to the store to buy a \"coke\""; String B = A.replaceAll(REGEX,"Pepsi"); Something like this. Ok. So what you want is to search, within a String, for a sequence of characters starting and ending with double-quotes? String

StringFormat is ignored

混江龙づ霸主 提交于 2019-11-29 05:31:19
This is my binding (shortened, Command-Property is also bound) <MenuItem Header="Key" CommandParameter="{Binding StringFormat='Key: {0}', Path=PlacementTarget.Tag, RelativeSource={RelativeSource AncestorType=ContextMenu}}"/> The Tag-Property of ContectMenu's PlacementTarget is a String like "Short.Plural" What i expect to receive in the Command-Handler is: Key: Short.Plural But what i acutally receive is: Short.Plural Label does not use StringFormat but ContentStringFormat. Use it this way: <TextBlock x:Name="textBlock" Text="Base Text"/> <Label Content="{Binding Path=Text, ElementName

Differentiate String Literal from Char Array

冷暖自知 提交于 2019-11-29 02:57:38
I want to write some function that takes a string literal - and only a string literal: template <size_t N> void foo(const char (&str)[N]); Unfortunately, that is too expansive and will match any array of char - whether or not it's a true string literal. While it's impossible to tell the difference between these at compile-time - without having to resort to requiring the caller to wrap the literal/array - at run-time, the two arrays will be in entirely different places in memory: foo("Hello"); // at 0x400f81 const char msg[] = {'1', '2', '3'}; foo(msg); // at 0x7fff3552767f Is there a way to