header-files

what is the difference between “constexpr” and “static constexpr” variables of the non-class type in a header file?

牧云@^-^@ 提交于 2019-12-24 01:53:04
问题 I have a header file test.hxx which will be included in multiple translation units. The header file is as below: namespace program_exec { static constexpr int DEFAULT_VAL = 0; static constexpr char *name = "proc_exec"; } I have included this header file in multiple translation units (*.cxx) and it works fine. But removing the static infront of constexpr char* causes a linking error i.e, if I change the static constexpr char *name = "proc_exec" to constexpr char *name = "proc_exec"; I am

Why do class member functions defined outside the class (but in header file) have to be inlined?

狂风中的少年 提交于 2019-12-24 01:45:54
问题 I have read existing answers on the two meanings of inline, but I am still confused. Let's assume we have the following header file: // myclass.h #ifndef INCLUDED_MYCLASS #define INCLUDED_MYCLASS class MyClass { public: void foo(); // declaration }; inline void MyClass::foo() { // definition } #endif Why does void foo() which is defined outside the class in the file, have to be explicitly defined with inline ? 回答1: It's because you defined MyClass::foo in a header file. Or a bit more abstract

Do all C functions need to be declared in a header file

人盡茶涼 提交于 2019-12-24 01:38:36
问题 Do I need to declare all functions I use in a .c file in a header file, or can I just declare and define right there in the .c file? If so, does a definition in the .c file in this case count as the declaration also? 回答1: For the compiler, it does not matter if a declaration occurs in a .h or a .c file, because the compiler sees the preprocessed form. For the human developer reading and contributing to your code, it is much better (to avoid copy&pasting the same declaration twice) to put the

When archiving app Xcode complains about missing files

风格不统一 提交于 2019-12-23 12:57:08
问题 I'm using an external library (RHAddressBook) when I run the app in the simulator or in device there is no issue. But when I choose to archive the app I run into the issue where it's saying 'RHAddressBook/AddressBook.h' file not found at the line #import <RHAddressBook/AddressBook.h> I have checked that the header search paths are the same for debug and release. Not really sure what to check else. 回答1: When you setup the use of the external library for your development builds, you may have

Can VS 2010 check/update header files automatically?

可紊 提交于 2019-12-23 12:54:57
问题 That's pretty much my question: can VS 2010 check and update header files in C++ code automatically? And can VS 2010 automatically generate a cpp file from a header file, saving you the time to copy the function definitions from the header file? I mean, can it figure that there's no implementation for some method and generate an empty stub from the declaration found in the header file? Thanks! CFP. 回答1: No this feature does not exist in the Visual Studio C++ implementation. Changes to a

Invalid Operands to binary / (have 'int *' and 'int')?

折月煮酒 提交于 2019-12-23 12:14:31
问题 Every time I try this: long crypt(int *integer) { printf("Enter five digit integer:\n"); scanf("%i",integer); int digit1=integer/10000; int digit2=(integer%10000)/1000; int digit3=(integer%1000)/100; int digit4=(integer%100)/10; int digit5=(integer%10)/1; const char *digit1c[10]; const char *digit2c[10]; const char *digit3c[10]; const char *digit4c[10]; const char *digit5c[10]; (There's more but this seems to be the problem, I'll add the rest by request.) then it return this error: math2.h:44

Invalid Operands to binary / (have 'int *' and 'int')?

隐身守侯 提交于 2019-12-23 12:11:24
问题 Every time I try this: long crypt(int *integer) { printf("Enter five digit integer:\n"); scanf("%i",integer); int digit1=integer/10000; int digit2=(integer%10000)/1000; int digit3=(integer%1000)/100; int digit4=(integer%100)/10; int digit5=(integer%10)/1; const char *digit1c[10]; const char *digit2c[10]; const char *digit3c[10]; const char *digit4c[10]; const char *digit5c[10]; (There's more but this seems to be the problem, I'll add the rest by request.) then it return this error: math2.h:44

Without including #include <ctype.h>

北战南征 提交于 2019-12-23 11:50:31
问题 I have written the below programs without including #include <ctype.h> . I am able to execute the program. Where are these prototypes declared? I am using gcc . 1. #include <stdio.h> int main() { if(isalnum(';')) printf("character ; is not alphanumeric"); if(isalnum('A')) printf("character A is alphanumeric "); return 0; } 2. #include <stdio.h> int main() { printf("Lower case of A is %c \n", tolower('A')); printf("Lower case of 9 is %c \n", tolower('9')); printf("Lower case of g is %c \n",

GDB: error setting break point in template class functions in header files

不羁岁月 提交于 2019-12-23 08:47:02
问题 I have used two different versions of GDB, both give problems in the following code: Trimmed down code in MyFile.h : template<class T> struct ABC: PQR<T> { void flow(PP pp) { const QX qx = XYZ<Z>::foo(pp); // Trying to set a breakpoint here, line no. 2533 ASSERTp(qx >= last_qx()); } } GDB 7.1: Reading symbols from /path_to_exec/exec...done. (gdb) break MyFile.h:2533 Note: breakpoint 1 also set at pc 0x121. Note: breakpoint 1 also set at pc 0x121. Note: breakpoint 1 also set at pc 0x121. Note:

Header Files in Multiple Directories: Best Practices

こ雲淡風輕ζ 提交于 2019-12-23 07:57:53
问题 I'm a C Newb I write lots of code in dynamic languages (javascript, python, haskell, etc.), but I'm now learning C for graduate school and I have no idea what I'm doing. The Problem Originally I was building all my source in one directory using a makefile, which has worked rather well. However, my project is growing and I would like to split the source into multiple directories (unit tests, utils, core, etc.). For example, my directory tree might look like the following: . |-- src | |-- foo.c