Hi,
I ran across the following #define in some documentation for an
embedded system (I truncated the actual define, but the general form is
intact).
#define PADDING \
"x-00: ab\r\n"\
"x-01: ab\r\n"\
"x-0F: ab"
and I'd like to convert it to a const. Unfortunately, my C/C++ is a
little rusty (well, maybe a lot rusty) and I'm not quite sure what an
equivalent "const" form might be for this thing. Would something like
the following work?
const char PADDING[] = {
'"','x','-','0','0',':',' ','a','b','\r','\n','"',
'"','x','-','0','1',':',' ','a','b','\r','\n','"',
'"','x','-','0','F',':',' ','a','b','"'
};
Any help would be greatly appreciated.
Thanks,
:Paul 4 1532
Paul Erion wrote: I ran across the following #define in some documentation for an embedded system (I truncated the actual define, but the general form is intact).
#define PADDING \ "x-00: ab\r\n"\ "x-01: ab\r\n"\ "x-0F: ab"
and I'd like to convert it to a const. Unfortunately, my C/C++ is a little rusty (well, maybe a lot rusty) and I'm not quite sure what an equivalent "const" form might be for this thing. Would something like the following work?
const char PADDING[] = { '"','x','-','0','0',':',' ','a','b','\r','\n','"', '"','x','-','0','1',':',' ','a','b','\r','\n','"', '"','x','-','0','F',':',' ','a','b','"' };
Any help would be greatly appreciated.
You don't have to do it one by one character, you may use a literal to
initialise a character array:
const char PADDING[] = "x-00: ab\r\nx-01: ab\r\nx-0F: ab";
besides, you missed the terminator character, and the literal will put
it in.
V
"Paul Erion" <pe****@gmail.com> wrote in message
news:11**********************@l41g2000cwc.googlegr oups.com... Hi,
I ran across the following #define in some documentation for an embedded system (I truncated the actual define, but the general form is intact).
#define PADDING \ "x-00: ab\r\n"\ "x-01: ab\r\n"\ "x-0F: ab"
and I'd like to convert it to a const. Unfortunately, my C/C++ is a little rusty (well, maybe a lot rusty) and I'm not quite sure what an equivalent "const" form might be for this thing. Would something like the following work?
const char PADDING[] = { '"','x','-','0','0',':',' ','a','b','\r','\n','"', '"','x','-','0','1',':',' ','a','b','\r','\n','"', '"','x','-','0','F',':',' ','a','b','"' };
That's the hard way. :-)
Remember that adjacent string literals will be concatenated
at compile time (but an individual literal cannot be broken
between lines)
const char PADDING[] =
{
"blah blah blah"
"yada yada yada"
"etc. etc. etc."
};
or
const char *PADDING =
"blah blah blah"
"yada yada yada"
"etc. etc. etc." ;
In the second case, you might also want to qualify the
pointer itself as const, to prevent inadvertently changing
it to point elsewhere:
const char * const PADDING =
"blah blah blah"
"yada yada yada"
"etc. etc. etc." ;
HTH,
-Mike
Thanks Mike and Victor! I'm (really) glad there is a much simpler way
of constructing that string -- it seems as if I always stumble across
the most tedious method first. And, now knowing that the compiler
concatenates adjacent strings, that #define makes sense (and means that
I was way off base by including the quote character, ", in the const
string).
:Paul
"Paul Erion" <pe****@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com... Thanks Mike and Victor! I'm (really) glad there is a much simpler way of constructing that string -- it seems as if I always stumble across the most tedious method first. And, now knowing that the compiler concatenates adjacent strings, that #define makes sense (and means that
I was way off base by including the quote character, ", in the const string).
Yes, I thought about that after I posted my reply, but
I supposed you would have figured it out when you saw
the quotes appear in your output. And the lack of a
terminator character ('\0)' (Victor noticed it, I didn't),
could have caused some interesting effects. :-)
-Mike This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Anon Email |
last post by:
Hey people,
This looks really weird. I can't make sense of it. Is this a mistake?
Can anyone help?
IStack const & GetStack () const;
Cheers,
|
by: G Patel |
last post by:
Can people please comment on the layout/style of my problem? The major
issue I had was the layout. I ended up having to put a relatively
large switch statement, inside an if statement, which is...
|
by: cs_hart |
last post by:
I have an application in Java that I would like to port to c++ to
integrate with existing c++ app. Is anyone aware of any tools to help?
I found microsft has a java->c# convert, but the java app...
|
by: Sam Steingold |
last post by:
the following program does not compile with g++ 4.1.1:
====================================================
// $Id$
// $Source$
#include <stdint.h>
#include <stdio.h>
typedef struct {...
|
by: canoewhiteh2o |
last post by:
I am converting a couple of C header files to C#. It is mainly just a
bunch C structs but I am not sure how to handle the #ifdef and #ifndef
in C#. For example:
#ifndef DATE_TIME
#define...
|
by: nickyeng |
last post by:
I have written 3 files, i dont know whether i do it correctly or wrongly but somehow it compiled well and can run.
My simple aim is to display the terrain.txt file into the terrain array, and then...
|
by: cmdolcet69 |
last post by:
Can anyone give me some ideas on how to convert the following program
to vb 2003? I would like to jsut take this code and implement it in
vb.
def.h
/* Global Type Definitions */
typedef ...
|
by: er |
last post by:
hi,
the code below generates the following behavior. cld someone please
help understand it?
1) clean project + build project generates build errors (see bottom)
2) build a second time, errors...
|
by: cablepuff |
last post by:
template <typename ContainerType>
ContainerType rsa_encrypt_list(const std::string&, const typename
ContainerType::reference, const typename ContainerType::reference);
const BigInteger...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |