Why does (int)55 == 54 in C++?

前端 未结 8 1276
旧巷少年郎
旧巷少年郎 2020-12-31 01:32

So I\'m learning C++. I\'ve got my \"C++ Programming Language\" and \"Effective C++\" out and I\'m running through Project Euler. Problem 1...dunzo. Problem 2...not so mu

8条回答
  •  南笙
    南笙 (楼主)
    2020-12-31 01:48

    I know this is not going to help with your real question, but you mentioned you're learning C++. I would recommend keeping as close to ANSI as possible, for learning purposes. I think that's /Za on MSVC (which is what you're probably using), or -ansi -pedantic on GCC.

    In particular, you should be using one of these signatures for main until you have a good (platform-specific) reason to do otherwise:

    int main(int argc, char *argv[]);
    int main(int argc, char **argv); // same as the first
    int main();
    

    ...instead of any platform-specific version, such as this (Windows-only) example:

    #include  // defines _TCHAR and _tmain
    int _tmain(int argc, _TCHAR* argv[]); // win32 Unicode vs. Multi-Byte
    

提交回复
热议问题