visual-c++

Weird LNK2001 errors after migration to VS2019

限于喜欢 提交于 2020-08-10 18:57:50
问题 After moving my code from VS2017 to VS2019 I stumbled into strange linker behaviour -- it seems like it references objects from static library that it shouldn't have (which in turn refer to symbols that can't be resolved). Basically, I end up with this: 1>tools.lib(object_storage_azure.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl azure::storage::operation_context::operation_context(void)" (__imp_??0operation_context@storage@azure@@QEAA@XZ) 1>tools

wchar_t* with UTF8 chars in MSVC

梦想的初衷 提交于 2020-08-07 18:27:15
问题 I am trying to format wchar_t* with UTF-8 characters using vsnprintf and then printing the buffer using printf . Given the following code: /* This code is modified version of KB sample: https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_73/rtref/vsnprintf.htm The usage of `setlocale` is required by my real-world scenario, but can be modified if that fixes the issue. */ #include <wchar.h> #include <stdarg.h> #include <stdio.h> #include <locale.h> #ifdef MSVC #include <windows.h> #endif

wchar_t* with UTF8 chars in MSVC

…衆ロ難τιáo~ 提交于 2020-08-07 18:26:29
问题 I am trying to format wchar_t* with UTF-8 characters using vsnprintf and then printing the buffer using printf . Given the following code: /* This code is modified version of KB sample: https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_73/rtref/vsnprintf.htm The usage of `setlocale` is required by my real-world scenario, but can be modified if that fixes the issue. */ #include <wchar.h> #include <stdarg.h> #include <stdio.h> #include <locale.h> #ifdef MSVC #include <windows.h> #endif

std::from_chars doens't compile under MSVC

江枫思渺然 提交于 2020-08-06 05:07:22
问题 I have a little function that uses std::from_chars to create a date object from a std::string_view , while it compiles using clang or gcc under ubuntu it doesn't using msvc under windows. date::year_month_day parseDate(const std::string_view& s) { int y { 0 }, m { 0 }, d { 0 }; std::from_chars(s.begin(), s.begin() + 4, y); std::from_chars(s.begin() + 5, s.begin() + 7, m); std::from_chars(s.begin() + 8, s.begin() + 10, d); return date::year { y } / m / d; } For each of std::from_chars call the

What is stored in this 26KB executable?

自作多情 提交于 2020-08-01 05:59:08
问题 Compiling this code with -O3 : #include <iostream> int main(){std::cout<<"Hello World"<<std::endl;} results in a file with a length of 25,890 bytes. (Compiled with GCC 4.8.1) Can't the compiler just store two calls to write(STDOUT_FILENO, ???, strlen(???)); , store write 's contents, store the string, and boom write it to the disk? It should result in a EXE with a length under 1,024 bytes to my estimate. Compiling a hello world program in assembly results in 17 bytes file: https:/

Why can braced-init-list not be used in ternary operator?

余生颓废 提交于 2020-07-28 08:48:47
问题 My compiler is the latest VC++ 2013 RC. int f(bool b) { return {}; // OK return b ? 1 : { }; // C2059: syntax error : '{' return b ? 1 : {0}; // C2059: syntax error : '{' return b ? {1} : {0}; // C2059: syntax error : '{' } Why can braced-init-list not be used in ternary operator? Is this behavior defined as ill-formed by the C++ standard, or just a bug of the VC++ compiler? 回答1: Well, here's what the standard says about the braced-init-list (8.5.3.1): List-initialization can be used as the

Why not use __if_exists with local variables?

五迷三道 提交于 2020-07-23 04:27:41
问题 The MSDN documentation for the Microsoft-specific __if_exists statement says the following (emphasis added): Apply the __if_exists statement to identifiers both inside or outside a class. Do not apply the __if_exists statement to local variables . Unfortunately there is no explanation for why you should not apply this to local variables. It compiles fine and has the expected effect, so I'm wondering if anyone knows why they say not to do this. Is it a correctness issue, or a maintainability

Why not use __if_exists with local variables?

痞子三分冷 提交于 2020-07-23 04:25:44
问题 The MSDN documentation for the Microsoft-specific __if_exists statement says the following (emphasis added): Apply the __if_exists statement to identifiers both inside or outside a class. Do not apply the __if_exists statement to local variables . Unfortunately there is no explanation for why you should not apply this to local variables. It compiles fine and has the expected effect, so I'm wondering if anyone knows why they say not to do this. Is it a correctness issue, or a maintainability

Reusable member function in C++

烈酒焚心 提交于 2020-07-20 10:05:23
问题 I'm using this member function to get pointer to object: virtual Object* Create() { return new Object(); } It's virtual so I can get pointer to derived objects, now I'm doing it like this: virtual Object* Create() { return new Foo(); } It is working correctly, but I'd like to do something like this to prevent any mistakes and also to make it easier so I don't have to rewrite that function every time I make new class: virtual Object* Create() { return new this(); } I was trying to find how to

Reusable member function in C++

馋奶兔 提交于 2020-07-20 10:03:47
问题 I'm using this member function to get pointer to object: virtual Object* Create() { return new Object(); } It's virtual so I can get pointer to derived objects, now I'm doing it like this: virtual Object* Create() { return new Foo(); } It is working correctly, but I'd like to do something like this to prevent any mistakes and also to make it easier so I don't have to rewrite that function every time I make new class: virtual Object* Create() { return new this(); } I was trying to find how to