I think you missed that in my first post: #define STRING_PREAMBLE @ #define STRINGIFY_(c) #c #define STRINGIFY(c) STRINGIFY_(c) Then: char *pidupdate=3DSTRINGIFY(STRING_PREAMBLE) ID "," posVal; You can stringify using the preprocessor # operator, buried under two levels of macro expansion. I did some tests and unfortunately it seems that it is not possible to convert a macro contents into a single-quote quoted character. Cheers, Isaac Em dom, 29 de set de 2019 14:23, Justin Richards escreveu: > I am not really sure how to STRINGFY. The gcc help file sect 3.4 > Stringification gives examples using double quotes. > > I tried defining without quotes which works ok when later wrapping with > double quotes > > but this character comparison fails > > #define STRING_PREAMBLE @ > if (payload[0] =3D=3D 'STRING_PREAMBLE' ) > > I think it is comparing payload[0] with the first char after the single > quote i.e 'S' > > and the compiler does not like double quotes as below > > if (payload[0] =3D=3D "STRING_PREAMBLE" ) > > nor does it like this > > if (payload[0] =3D=3D STRING_PREAMBLE) > > > On Sun, Sep 29, 2019 at 10:38 PM Isaac M. Bavaresco < > isaacbavaresco@gmail.com> wrote: > > > You cannot define STRING_PREAMBLE's at sign with double quotes. > > > > Define it without quotes and STRINGIFY it to use in the string > > concatenation, it will work. > > > > Then in the 'case', use: > > > > case 'STRING_PREAMBLE': > > > > It should work. > > > > Cheers, > > Isaac > > > > > > Em dom, 29 de set de 2019 11:28, Justin Richards < > > justin.richards@gmail.com> > > escreveu: > > > > > That line is actually part of a string that contains javascript that = is > > > embedded in html that is sent to the browser client when requested. > > > > > > so the plus signs are actually in the javascript code. > > > > > > server.sendContent(F("var arrpv=3D[];" > > > ... > > > "var pidupdate=3D' " STRING_PREAMBLE " ' +ID+ ' , ' +posVal; > > > console.log('pidupdate:'+pidupdate); " > > > ... > > > ")); > > > > > > I guess it would have been clearer if I said I want to do something > like > > > this > > > > > > #define STRING_PREAMBLE "@" > > > > > > strHTML[] =3D "sometext " STRING_PREAMBLE "someothertext" ; > > > > > > As best as I can tell the above expands to > > > > > > strHTML[] =3D "sometext " "@" "someothertext" > > > > > > and effectively produces > > > > > > strHTML[] =3D "sometext @someothertext" > > > > > > and works ok until I try > > > > > > if (payload[0] =3D=3D STRING_PREAMBLE) > > > > > > which expand to > > > > > > if (payload[0] =3D=3D "@") > > > > > > which the compiler does not like. > > > > > > I am using the Arduino IDE to compile code for the ESP8266. As best > as i > > > can tell the IDE/compiler accepts both C and C++ > > > > > > justin > > > > > > On Sun, Sep 29, 2019 at 8:35 PM Isaac M. Bavaresco < > > > isaacbavaresco@gmail.com> > > > wrote: > > > > > > > Are you using C++? > > > > > > > > Because in > > > > > > > > pidupdate=3D'"STRING_PREAMBLE"'+ID+','+posVal;console.log('pid > > > > update:'+pidupdate) > > > > > > > > The plus signs are not valid in C to concatenate strings, also, if > > posVal > > > > is a variable then even without the plus signs it would not work. > > > > > > > > In C you could write: > > > > > > > > #define STRING_PREAMBLE @ > > > > #define STRINGIFY_(c) #c > > > > #define STRINGIFY(c) STRINGIFY_(c) > > > > > > > > Then: > > > > > > > > char *pidupdate=3DSTRINGIFY(STRING_PREAMBLE) ID "," posVal; > > > > > > > > I just noticed you are using single quotes for some elements of the > > > > expression. I'm pretty sure you must be using C++. > > > > > > > > C++ is not C. They have important differences. > > > > > > > > Cheers, > > > > Isaac > > > > > > > > > > > > > > > > Em dom, 29 de set de 2019 05:03, Justin Richards < > > > > justin.richards@gmail.com> > > > > escreveu: > > > > > > > > > Using macros to make some code more readable and maintainable I > > always > > > > seem > > > > > to hit snags. > > > > > > > > > > Struggling to define the question, I have used examples below to > try > > > and > > > > > illustrate my query. > > > > > > > > > > I wanted to convert this > > > > > > > > > > if (payload[0] =3D=3D '@') > > > > > { > > > > > ... > > > > > } > > > > > > > > > > to > > > > > #define STRING_PREAMBLE '@' > > > > > > > > > > if (payload[0] =3D=3D STRING_PREAMBLE) > > > > > { > > > > > ... > > > > > } > > > > > > > > > > The compiler complains with "expected ')' before '@' > > > > > > > > > > So i tried variations on the theme > > > > > #define STRING_PREAMBLE @ > > > > > #define STRING_PREAMBLE "'@'" > > > > > #define STRING_PREAMBLE "@" > > > > > > > > > > The later two variations compiles but the following comparison > fails > > > > > if (payload[0] =3D=3D 'STRING_PREAMBLE') > > > > > > > > > > The macro is used elsewhere in the code as part of a string of > > embedded > > > > > HTML that embeds javascript and behaves as required > > > > > "var > > > > > > > > > > > > > > > > > > > > pidupdate=3D'"STRING_PREAMBLE"'+ID+','+posVal;console.log('pidupdate:'+pi= dupdate);" > > > > > > > > > > this was previously coded as > > > > > > > > > > "var > > pidupdate=3D'@'+ID+','+posVal;console.log('pidupdate:'+pidupdate);" > > > > > > > > > > Any hints or suggestions on how i should phrase my search. > > > > > > > > > > Justin > > > > > -- > > > > > http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive > > > > > View/change your membership options at > > > > > http://mailman.mit.edu/mailman/listinfo/piclist > > > > > > > > > -- > > > > http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive > > > > View/change your membership options at > > > > http://mailman.mit.edu/mailman/listinfo/piclist > > > > > > > -- > > > http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive > > > View/change your membership options at > > > http://mailman.mit.edu/mailman/listinfo/piclist > > > > > -- > > http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive > > View/change your membership options at > > http://mailman.mit.edu/mailman/listinfo/piclist > > > -- > http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .