linkage

C callback functions defined in an unnamed namespace?

£可爱£侵袭症+ 提交于 2019-12-06 00:21:44
问题 I have a C++ project that uses a C bison parser. The C parser uses a struct of function pointers to call functions that create proper AST nodes when productions are reduced by bison: typedef void Node; struct Actions { Node *(*newIntLit)(int val); Node *(*newAsgnExpr)(Node *left, Node *right); /* ... */ }; Now, in the C++ part of the project, i fill those pointers class AstNode { /* ... */ }; class IntLit : public AstNode { /* ... */ }; extern "C" { Node *newIntLit(int val) { return (Node*

C++ standard: ODR and constexpr std::string_view

回眸只為那壹抹淺笑 提交于 2019-12-05 23:22:03
If I have a header foo.h which contains #ifndef FOO_H_ #define FOO_H_ namespace foo { constexpr std::string_view kSomeString = "blah"; } #endif // FOO_H_ then is it safe to include foo.h from within multiple .cc files in a single program, regardless of what they do with the symbol kSomeString , or are there some uses that could cause an ODR violation? Also, is it guaranteed that kSomeString.data() will return the same pointer across .cc files? I'd like specific references to wording in the C++ standard if possible. Thanks! Merely including foo.h from multiple translation units will not violate

Implicit function declarations and linkage

会有一股神秘感。 提交于 2019-12-05 20:22:55
Recently I've learnt about implicit function declarations in C . The main idea is clear but I have some troubles with understanding of the linkage process in this case. Consider the following code ( file a.c ): #include <stdio.h> int main() { double someValue = f(); printf("%f\n", someValue); return 0; } If I try to compile it: gcc -c a.c -std=c99 I see a warning about implicit declaration of function f() . If I try to compile and link: gcc a.c -std=c99 I have an undefined reference error. So everything is fine. Then I add another file (file b.c ): double f(double x) { return x; } And invoke

What does “internal linkage” mean?

拟墨画扇 提交于 2019-12-05 15:52:51
In the standard it says that: When a name has internal linkage , the entity it denotes can be referred to by names from other scopes in the same translation unit. and: A name having namespace scope (3.3.6) has internal linkage if it is the name of — a variable, function or function template that is explicitly declared static; So consider the following code: #include <stdio.h> namespace A { /* a with internal linkage now. Entity denoted by a will be referenced from another scope. This will be main() function scope in my case */ static int a=5; } int main() { int a; //declaring a for unqualified

C and C++ linkage with extern “C”

爷,独闯天下 提交于 2019-12-05 14:21:21
I have a C++ function defined in a .h file as follows and implemented in a .cpp file: extern "C" void func(bool first, float min, float* state[6], float* err[6][6]) { //uses vectors and classes and other C++ constructs } How can I call func in a C file? How do I set up my file architecture / makefile to compile this? Thanks! To call it in C, all you need to do is call it normally. Because you told the compiler to use the C calling conventions and ABI with extern "C" , you can call it normally: func(args); To compiler, use this for the C++: g++ -c -o myfunc.o myfunc.cpp Then this for the C: gcc

template non type arguments

落花浮王杯 提交于 2019-12-05 02:14:54
$14.3.2 - "... A template-argument for a non-type, non-template template-parameter shall be one of: ...a constant expression (5.19) that designates the address of an object with static storage duration and external or internal linkage or a function with external or internal linkage..." In the code shown below, I fail to understand why 'name2' and 'name3' are not allowed as non type template arguments. I am using gcc 4.7.2 on Windows. Both 'name2' and 'name3' are names of array and hence are constant expressions. Further 'name2' is having internal linkage and 'name3' has both static and

External, internal and no linkage or why this does not work?

人盡茶涼 提交于 2019-12-04 22:41:56
According to C standard: In the set of translation units and libraries that constitutes an entire program, each declaration of a particular identifier with external linkage denotes the same object or function. Within one translation unit, each declaration of an identifier with internal linkage denotes the same object or function. Each declaration of an identifier with no linkage denotes a unique entity. In my example we have three separate declarations with each identifier having a different linkage.So why doesn't this work? static int a; //a_Internal int main(void) { int a; //a_Local { extern

Explain about linkages(external/internal) in c++?

天涯浪子 提交于 2019-12-04 16:48:57
Explain about linkages(external/internal) in c++? How does linkage differ for a function,constant,inline function,template function ,class and template class JaredPar Can you clarify your question a bit? C++ linkage is a pretty big topic and giving a complete answer in an SO post is probably a bit more information than you're looking for ( Litb may prove me wrong). Here is a link which provides a general overview of linkage: http://gaubuali.wordpress.com/linkage-in-c-and-c/ http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=41 check section 3.5 in standard http://www.open-std.org

How to do clustering using the matrix of correlation coefficients?

百般思念 提交于 2019-12-04 12:35:25
问题 I have a correlation coefficient matrix (n*n). How to do clustering using the correlation coefficient matrix? Can I use linkage and fcluster function in SciPy? Linkage function needs n * m matrix (according to tutorial), but I want to use n*n matrix. My code is corre = mp_N.corr() # mp_N is raw data (m*n matrix) Z = linkage(corre, method='average') # 'corre' is correlation coefficient matrix fcluster(Z,2,'distance') Is this code right? If this code is wrong, how can I do clustering with

template External Linkage ?can anyone Explain this?

≡放荡痞女 提交于 2019-12-04 12:31:33
问题 A template name has linkage (3.5). A non-member function template can have internal linkage; any other template name shall have external linkage. Entities generated from a template with internal linkage are distinct from all entities generated in other translation units. I know about external linkage using the keyword extern "C" EX : extern "C" { template<class T> class X { }; } but they gave template shall not have a C linkage what actually meant for the above statement? can any one explain