extern

Switching Between External Aliases Without Re-Writing Code?

南笙酒味 提交于 2019-12-14 02:13:03
问题 extern alias dll1; extern alias dll2; ... public void DoStuff1(){ dll1::NameSpace.Class.Method(); } public void DoStuff2(){ dll2::NameSpace.Class.Method(); } What I'd like to be able to do is: public void DoStuff(alias a){ a::NameSpace.Class.Method(); } alias does not appear to be usable like this. Addendum: dll1 and dll2 are different versions of the same dll. 回答1: Keep code from different aliases in different files, and use partial classes in each file. (Partial classes allow you to write

What happens if I use extern “C++” with a C toolchain?

天大地大妈咪最大 提交于 2019-12-14 00:56:07
问题 My question is mainly about the fact that a C++ toolchain "understands" both C and C++, so if I feed some code with an extern "C" to a c++ toolchain I assume it can understand what to do with that; but what if I feed code with extern "C++" to a C toolchain ? What is the expected behaviour ? 回答1: If the compiler ALSO understands C++, it may accept it. If it's a pure C compiler it will object (just like it will on extern "C" as that syntax is not valid C - this is why it's typically enclosed

Assigning {pointer to function with C linkage} to {pointer to function with C++ linkage} and vice versa

二次信任 提交于 2019-12-13 16:24:41
问题 Is this code legal? extern "C" typedef void (ft_blah_c)(); /*extern "C++"*/ typedef void (ft_blah_cpp)(); extern "C" void fn_blah_c() {} /*extern "C++"*/ void fn_blah_cpp() {} ft_blah_c *g_Blah_c = fn_blah_cpp; // <--- ? ft_blah_cpp *g_Blah_cpp = fn_blah_c; // <--- ? I have real code with similiar assigments, it compiles and executes without any problems (MSVC 2010). 回答1: In general that should not work. The problem is that when you call fn_blah_c or fn_blah_cpp directly the compiler knows

Redefinition; different basic types (typedef struct)

一世执手 提交于 2019-12-13 11:58:03
问题 I'm having a bit of trouble trying to get structs to work properly when they are defined in different files. From as far as I can tell, the error is telling me that the struct is being defined two different times. I believe that perhaps I may need to use extern somewhere? I've tried experimenting and looking for help on Google, but to no avail. Any help at all would be most appreciated, thank you. All four of my files are below. FILE: Foo.h typedef struct { int number; } my_struct; //

c99 inline semantics with gcc (mspgcc)

流过昼夜 提交于 2019-12-13 11:51:19
问题 I am writing a couple of functions that I would like to inline. Reading here and using the second c99 inline option with inline on all declarations and definitions, like so: extern inline void SPFD54124B_write_cmd(uint16_t command); in a header, and inline void SPFD54124B_write_cmd(uint16_t command) { spi_write(command, CMD_WIDTH); } in a corresponding c file. I was expecting to get inlined versions of the functions. But when I compile i get: Generating dependencies dep/spi.d from src/spi.c

AJAX post to external url [duplicate]

白昼怎懂夜的黑 提交于 2019-12-13 09:13:53
问题 This question already has answers here : How do I send a cross-domain POST request via JavaScript? (17 answers) Closed 6 years ago . I am trying to post data with ajax to an external url with the following code: $(document).ready(function(){ $('.submit_button').click(function() { $.ajax({ type : 'POST', url : 'http://site.com/post.php', dataType : 'text', data: $("#infoForm").serialize() }).done(function(results) { alert(results); }); event.preventDefault(); }); }); But I am getting the

C++ How to share constants with extern between cpp - Error: storage class specified

浪子不回头ぞ 提交于 2019-12-13 02:16:15
问题 I've the header file in which I declare some constants with extern: #ifndef CONSTANTS_H #define CONSTANTS_H #include <string> class Constants { public: Constants(){} extern const std::string DELIMITER; extern const std::string FILENAME; extern const int BLUCAR; extern const int REDCAR; extern const int EMPTY; extern const int SPARSE_LIM; protected: private: }; #endif // CONSTANTS_H Then in the source I define them like this: #include "constants.h" extern const std::string DELIMITER = ",";

CUDA extern texture declaration

丶灬走出姿态 提交于 2019-12-13 01:27:34
问题 I want to declare my texture once and use it in all my kernels and files. Therefore, I declare it as extern in a header and include the header on all other files (following the SO How do I use extern to share variables between source files?) I have a header cudaHeader.cuh file containing my texture: extern texture<uchar4, 2, cudaReadModeElementType> texImage; In my file1.cu , I allocate my CUDA array and bind it to the texture: cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc< uchar4

Implementing extern WINAPI call in MFC C++ App

落花浮王杯 提交于 2019-12-13 00:47:22
问题 I am working with Windows Form App C++ . I have to use some header file that has HRESULT extern WINAPI StartUp ( DWORD dwVRequired, LPVERSION lpVersion); I have to execute this method within Form1.h private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) { APPVERSION version; HRESULT result = APPStartUp(APP_VERSIONS, &version); } But I am getting the compile error like this Error 1 error LNK2028: unresolved token (0A000025) "extern "C" long __stdcall APPStartUp(unsigned

What are potential disadvantages of using extern “C”?

笑着哭i 提交于 2019-12-12 18:51:10
问题 I have read When to use extern "C" in C++? In C++ source, what is the effect of extern "C"? Why do we need extern "C"{ #include <foo.h> } in C++? However, one question that I have not found an answer to: are there (potentially, future) disadvantages to using extern "C" (e.g., on as many functions as possible)? To be more specific: Is there any disadvantage in adding extern "C" to functions whose interface only use C functionality; in other words, those that do not use the features listed in