macros

Allow use of member variable depending on preprocessor directives

无人久伴 提交于 2020-08-26 10:07:13
问题 Consider the following class: class Foo { public: #ifdef CONDITION int x = 0; #endif int y; int foo() { #ifdef CONDITION return ++x; #else return 0; #endif } } int x only exists when I define CONDITION - either through a #define CONDITION or as a preprocessor definition ( -D CONDITION ) This has the neat advantage that I can't compile it I use x by mistake somewhere when CONDITION isn't defined. For example: If, by mistake, I write something like: Foo f; f.x = 10; This will not be allowed to

Digraph and trigraph can't work together?

拜拜、爱过 提交于 2020-08-25 07:05:02
问题 I'm learning digraph and trigraph, and here is the code which I cannot understand. (Yes, I admit that it's extremely ugly.) This code can compile: #define _(s) s%:%:s main(_(_)) <% __; %>t This code can compile, too: #define _(s) s??=??=s main(_(_)) <% __; %> However, neither of the following two pieces of code can compile: #define _(s) s%:??=s main(_(_)) <% __; %> And #define _(s) s??=%:s main(_(_)) <% __; %> This does confuse me: Since the first two pieces of code can compile, I suppose the

C Macro to convert a string to a pascal string type

别等时光非礼了梦想. 提交于 2020-08-12 03:04:13
问题 I would like some ideas for a macro to convert a preprocessor defined string to a pascal type string and then be able to use the macro to initialize const char arrays and the like. Something like this would be great: #define P_STRING_CONV(str) ...???... const char *string = P_STRING_CONV("some string"); struct { char str[30]; ... }some_struct = {.str = P_STRING_CONV("some_other_string")}; I already tried something like this: #define DEFINE_PASCAL_STRING(var, str, strlen) struct {uint8_t len;

C Preprocessor: Own implementation for __COUNTER__

断了今生、忘了曾经 提交于 2020-07-29 06:38:26
问题 I'm currently using the __COUNTER__ macro in my C library code to generate unique integer identifiers. It works nicely, but I see two issues: It's not part of any C or C++ standard. Independent code that also uses __COUNTER__ might get confused. I thus wish to implement an equivalent to __COUNTER__ myself. Alternatives that I'm aware of, but do not want to use: __LINE__ (because multiple macros per line wouldn't get unique ids) BOOST_PP_COUNTER (because I don't want a boost dependency) BOOST

VBA - Calling from another workbook

爷,独闯天下 提交于 2020-07-20 04:07:24
问题 Trying to delete sheets based on data from another workbook sheet - By comparing and accessing data from another workbook sheet, however its not working. I was able to do it if the sheet was in the same workbook, however i do not want to import the worksheet every time. Code so far, My problem is calling from another workbook sheet. sub delete() Dim wb As Workbook Dim wks As Worksheet Dim MyRange As Range Dim Cell As Range Set wb = Workbooks("name.xlsx") Set wks = wb.Worksheets("allnames")

VBA to fetch html URL from webpage

对着背影说爱祢 提交于 2020-07-11 05:28:42
问题 I have created Macro which can read all the HTML of provided URL, however I want to fetch all the url from that HTML. Sub GetHTML_Click() Dim ie As InternetExplorer Dim html As HTMLDocument Dim j As Integer Set ie = New InternetExplorer ie.Visible = True url = Cells(1, 2) ie.navigate url Do While ie.READYSTATE <> READYSTATE_COMPLETE Application.StatusBar = "Trying to go to website ..." Loop Application.StatusBar = " " Set html = ie.document 'Dim htmltext As Collection Dim htmltext As String