macros

How do I deal with required Clojurescript code from Clojurescript macros?

风流意气都作罢 提交于 2021-02-07 11:51:46
问题 Let us say I have a X.clojurescript and a X.clojure namespace. Everything in X.clojurescript is Clojurescript code, everything in X.clojure is Clojure code. Unfortunately, I cannot define macros directly in Clojurescript, I have to define them in Clojure and then bring them into a Clojurescript namespace using (ns X.clojurescript.abc (:require-macros [X.clojure.def :as clj])) This is fine. However, what if the macro (defined in X.clojure) is going to need to reference something defined in a

How do I unit test clojure.core.async go macros?

a 夏天 提交于 2021-02-06 15:24:30
问题 I'm trying to write unit tests when using core.async go macros. Writing the test naively, as follows, appears that the code inside the go blocks doesn't get executed. (ns app.core-test (:require [clojure.test :refer :all] [clojure.core.async :as async])) (deftest test1 [] (let [chan (async/chan)] (async/go (is (= (async/<! chan) "Hello"))) (async/go (async/>! chan "Hello")))) I've managed to get the following working, but it's extremely hacky. (deftest test1 [] (let [result (async/chan) chan

How do I unit test clojure.core.async go macros?

点点圈 提交于 2021-02-06 15:20:49
问题 I'm trying to write unit tests when using core.async go macros. Writing the test naively, as follows, appears that the code inside the go blocks doesn't get executed. (ns app.core-test (:require [clojure.test :refer :all] [clojure.core.async :as async])) (deftest test1 [] (let [chan (async/chan)] (async/go (is (= (async/<! chan) "Hello"))) (async/go (async/>! chan "Hello")))) I've managed to get the following working, but it's extremely hacky. (deftest test1 [] (let [result (async/chan) chan

Templated function with two type parameters fails compile when used with an error-checking macro

心已入冬 提交于 2021-02-05 11:35:10
问题 Because someone in our group hates exceptions (let's not discuss that here), we tend to use error-checking macros in our C++ projects. I have encountered an odd compilation failure when using a templated function with two type parameters. There are a few errors (below), but I think the root cause is a warning: warning C4002: too many actual parameters for macro 'BOOL_CHECK_BOOL_RETURN' Probably best explained in code: #include "stdafx.h" template<class A, class B> bool DoubleTemplated(B &

How do I make macro constants globally accessible in C?

半世苍凉 提交于 2021-02-05 09:19:25
问题 I have some macro constants defined in a .c file and a .h file as follows: #define LOCAL_L2_BASE_LV (0x00800000UL) in .c file and #define FPGA_PLI_FEEDBACK_OFFSET_LV_FREQUENCY (0x00007000UL) in .h file I would like to use these constants in a different header file. What is the best way to do so? My initial idea was to use extern in the header file I want to use the constants in, but is this valid? 回答1: Macros can not be made extern, they are not variables. They are simply textual replacements

How can I make method chaining fluent in C?

Deadly 提交于 2021-02-05 05:46:06
问题 There is an existing C API that looks like this: //data typedef struct {int properties;} Widget; //interface Widget* SetWidth(Widget *const w, int width){ // ... return w; } Widget* SetHeight(Widget *const w, int height){ // ... return w; } Widget* SetTitle(Widget *const w, char* title){ // ... return w; } Widget* SetPosition(Widget *const w, int x, int y){ // ... return w; } The first parameter is always a pointer to the instance, and the functions that transform the instance always return

Options for defining preprocessor macros with parameters for entire project or solution in Visual Studio

Deadly 提交于 2021-02-04 18:30:08
问题 I want some macros having parameters to be available in all files in a project or better a complete solution. In VS2010, if I add them to the Preprocessor Definitions in properties->Configuration Properties->C/C++->Preprocessor using something like SQUARE(x)=((x)*(x));CUBE(x)=(SQUARE(x)*x); the macro definitions are not used by the compiler. However the approach may be close since IntelliSense provides the correct definitions when I hover over the macros in the source code. Is there a way to

Stringizing with __FUNCTION__ not working

一个人想着一个人 提交于 2021-01-29 20:09:50
问题 Simlar question with LINE But when I replaced __LINE__ with __FUNCTION__ . Macro concat string literal " __FUNCTION__ " and not actual function name. 回答1: __FUNCTION__ is not a macro, it's an implicitly declared static array. The same is true for __func__ , __PRETTY_FUNCTION__ , etc. Thus # can't work on it. If you want to concatenate something to it, you'll have to do that at runtime. 来源: https://stackoverflow.com/questions/65798613/stringizing-with-function-not-working

How to comment out chunk of code in multi-line macro?

泄露秘密 提交于 2021-01-29 05:37:39
问题 I have a complex multi line macro code in C++ (that process some geometry and computes its physical properties in RT) which is used many times and can not be converted to function (without huge space and performance hits). The problem is I sometimes need to configure the code inside disabling parts of code (in compile time for specific tasks/machines) something like this: #define some_macro \ bla; \ bla; \ if (0) \ { \ bla; \ bla; \ bla; \ } \ bla; As you can see this leads to multiples of

nmake modify macro based on target

坚强是说给别人听的谎言 提交于 2021-01-29 04:42:45
问题 I've got a Makefile.mak where I optionally create a test.exe or a DLL from my C-based source code. I'm using CL.EXE and NMAKE. I'd like to modify my CFLAGS macro like this when the target is TEST.EXE: CFLAGS = $(CFLAGS) -DMAIN And, of course, I use this in my C code: #ifdef MAIN ... int main()... yada yada #endif I had tried !IF $@ == "test.exe" but it crashed out and doesn't work logically since the $@, target, isn't deterministic in that part of the makefile. The logical place to define the