How to define string literal union type from constants in Typescript

To get the type of a variable you need to use the typeof type operator: const MY_CONSTANT = ‘MY_CONSTANT’ // must be const, no annotation. let or var will not work const SOMETHING_ELSE = ‘SOMETHING_ELSE’ // must be const, no annotation. let or var will not work type MyType = typeof MY_CONSTANT | typeof SOMETHING_ELSE … Read more

Why do (only) some compilers use the same address for identical string literals?

This is not undefined behavior, but unspecified behavior. For string literals, The compiler is allowed, but not required, to combine storage for equal or overlapping string literals. That means that identical string literals may or may not compare equal when compared by pointer. That means the result of A == B might be true or … Read more

Computing length of a C string at compile time. Is this really a constexpr?

Constant expressions are not guaranteed to be evaluated at compile time, we only have a non-normative quote from draft C++ standard section 5.19 Constant expressions that says this though: […]>[ Note: Constant expressions can be evaluated during translation.—end note ] You can assign the result to constexpr variable to be sure it is evaluated at … Read more

String literals: Where do they go?

A common technique is for string literals to be put in “read-only-data” section which gets mapped into the process space as read-only (which is why you can’t change it). It does vary by platform. For example, simpler chip architectures may not support read-only memory segments so the data segment will be writable. Rather than try … Read more

Windows path in Python

you can use always: ‘C:/mydir’ this works both in linux and windows. Other posibility is ‘C:\\mydir’ if you have problems with some names you can also try raw string literals: r’C:\mydir’ however best practice is to use the os.path module functions that always select the correct configuration for your OS: os.path.join(mydir, myfile) From python 3.4 … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)