comp.lang.c++@googlegroups.com | Google Groups | ![]() |
Unsure why you received this message? You previously subscribed to digests from this group, but we haven't been sending them for a while. We fixed that, but if you don't want to get these messages, send an email to comp.lang.c+++unsubscribe@googlegroups.com. |
- Dealing with strings with NULL characters in the middle - 9 Updates
- priority queue - 4 Updates
- cmsg cancel <c31a4186-f63e-43e9-aa98-f42205b6a84c@googlegroups.com> - 2 Updates
- Template of a Visual Studio Project for coordinate transformations - 1 Update
- Why is Smiling a Donation? - 1 Update
Paavo Helde <myfirstname@osa.pri.ee>: Nov 27 05:29PM -0600 Chicken Mcnuggets <chicken@mcnuggets.com> wrote in > { > netstring.push_back(c_netstring[i]); > } I understand this is just helper code, but you can achieve the same in a bit shorter and more reliable way: const char c_netstring[] = "13:SCGI\01\0,Test"; std::vector<char> netstring { std::begin(c_netstring), std::end(c_netstring) }; |
Chicken Mcnuggets <chicken@mcnuggets.com>: Nov 28 01:05PM On 27/11/14 23:10, Ben Bacarisse wrote: > then *always* increments it. Are you certain that the condition that > ends the loop (it != raw_scgi_netstring.end()) is going to fire and not > be "skipped"? I've removed all the the manual iterator increments in the loop and replaced them with continue (which in hindsight is what I meant to do originally anyway). I still get the same error which is unfortunate. I'm a bit stuck here. I've changed the iterator to a const iterator just to make sure I'm not doing anything stupid with it by accident and I still get the out of range exception. I could loop through it manually but that kinda defeats the purpose of using C++ in the first place. I might as well just write C style code for this if I do that way which I'm attempting to avoid. > string. The std::string class has lots of member function that can help > with this sort of task. > <snip> Yeah I started off with std::string and using the const char and string length constructor but hit the same issue there as I did here with out of range exceptions. I assumed it was because it was getting confused with all the NULLs but from the looks of it it was something more than that since the vector is exhibiting something similar. I can't keep swapping backwards and forwards. I'll stick with vector until I can get it working and then I'll think about a string implementation. I guess I could have a constructor for each so the user can choose how they want it stored internally if they like. Either way it can't hurt. |
Chicken Mcnuggets <chicken@mcnuggets.com>: Nov 28 04:18PM On 28/11/14 13:29, Stefan Ram wrote: > Someone writes: >> Subject: Dealing with strings with NULL characters in the middle > The ASCII character is spelled »NUL«. Ah. Yes. Thank you for the correction. |
Ben Bacarisse <ben.usenet@bsb.me.uk>: Nov 28 04:30PM Chicken Mcnuggets <chicken@mcnuggets.com> writes: <snip> > I still get the same error which is unfortunate. I'm a bit stuck > here. It's unlikely anyone can help without seeing the code. Ideally executable code. <snip> -- Ben. |
Chicken Mcnuggets <chicken@mcnuggets.com>: Nov 28 04:52PM On 28/11/14 13:05, Chicken Mcnuggets wrote: > implementation. I guess I could have a constructor for each so the user > can choose how they want it stored internally if they like. Either way > it can't hurt. Updated source code: http://ideone.com/3g6fW5 Produces the following output: Header Name: Header Value: Header Name: Header Value: Header Name: Header Value: Header Name: Header Value: Header Name: S Header Value: Header Name: SC Header Value: Header Name: SCG Header Value: Header Name: SCGI Header Value: Header Name: SCGI Header Value: Header Name: Header Value: Header Name: Header Value: Header Name: Header Value: Header Name: Header Value: Header Name: Header Value: Header Name: Header Value: The code works fine up until the NUL character and then fails for some reason. It appears that it doesn't see the NUL character as an individual character and then mucks up when you try and compare to it. I got rid of the iterators since that wasn't working and the new loop at least seems to produce some output to help with debugging. I've just run it through GDB and I think I've found the problem. My string that I am using is as follows: const char *c_netstring = "13:SCGI\01\0,Test"; Notice the first NUL character followed by a 1. In GDB it appears that the std::vector<char> interprets that as a single character (an ASCII 1 character aka SOH or Start of Heading or \001) rather than correctly interpreting it as an NUL (ASCII 0 or \000) followed by a 1 (ASCII 49 or \061). Now I know what the problem is. How do I fix this? I can't put a separator between the two characters because that would break the protocol so I'm kinda stuck here. |
Chicken Mcnuggets <chicken@mcnuggets.com>: Nov 28 04:53PM On 28/11/14 16:30, Ben Bacarisse wrote: > It's unlikely anyone can help without seeing the code. Ideally > executable code. > <snip> See my other post I just made with results from GDB and an explanation of what the problem is. |
Louis Krupp <lkrupp@nospam.pssw.com.invalid>: Nov 28 10:34AM -0700 On Fri, 28 Nov 2014 16:52:09 +0000, Chicken Mcnuggets <chicken@mcnuggets.com> wrote: <snip> >character aka SOH or Start of Heading or \001) rather than correctly >interpreting it as an NUL (ASCII 0 or \000) followed by a 1 (ASCII 49 or >\061). My reaction is probably the same as a lot of other folks: I should have seen that. This isn't a problem isn't with std::vector<char>; the compiler is handling the octal conversion \01 properly, and std::vector<char> is seeing the resulting byte. If I'm not mistaken, \1, \01 and \001 should all give the same result, a byte with a value of 1. >Now I know what the problem is. How do I fix this? I can't put a >separator between the two characters because that would break the >protocol so I'm kinda stuck here. \0001 should give you a nul byte followed by an ASCII '1'. Louis |
Chicken Mcnuggets <chicken@mcnuggets.com>: Nov 28 06:20PM On 28/11/14 17:34, Louis Krupp wrote: >> protocol so I'm kinda stuck here. > \0001 should give you a nul byte followed by an ASCII '1'. > Louis Awesome! That fixed that issue. Now I just need to fix my parser :P. Thank you everyone for your help, it is much appreciated. |
Paavo Helde <myfirstname@osa.pri.ee>: Nov 28 04:12PM -0600 Louis Krupp <lkrupp@nospam.pssw.com.invalid> wrote in > \0001 should give you a nul byte followed by an ASCII '1'. Another a bit more readable option would be const char *c_netstring = "13:SCGI\0" "1\0,Test"; or maybe something like #define NUL "\0" const char *c_netstring = "13:SCGI" NUL "1" NUL ",Test"; This defines a C array of 16 characters (the compiler adds one terminating zero byte automatically). hth Paavo |
Vincenzo Mercuri <invalid@world.net>: Nov 28 02:09AM +0100 Il 27/11/2014 22:31, Mr Flibble ha scritto: >> const calling the operator< potentially change the ordering :) > That might be the case but the *objects* inside the priority queue are > not const objects like the OP claimed. And how do you call objects that you cannot modify? -- Vincenzo Mercuri |
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Nov 28 01:30AM On 28/11/2014 01:09, Vincenzo Mercuri wrote: >> That might be the case but the *objects* inside the priority queue are >> not const objects like the OP claimed. > And how do you call objects that you cannot modify? But you can modify them. const int i = 42; /* (1) a const object */ int j = 43; /* (2) a non-const object */ const int& r = j; /* (3) a reference-to-const to a non-const object */ We are talking about case (3) here: the underlying container of priority_queue is std::vector by default and it is not possible to store const objects in a std::vector. Theoretically you can use const_cast<> on the priority_queue top() element to "remove const" and modify it and you should not run into any problems as long as that change doesn't affect ordering. /Flibble |
Vincenzo Mercuri <invalid@world.net>: Nov 28 03:24AM +0100 Il 28/11/2014 02:30, Mr Flibble ha scritto: > We are talking about case (3) here: the underlying container of > priority_queue is std::vector by default and it is not possible to store > const objects in a std::vector. That's where our misunderstanding lies. With "stored as const" I mean that they can only be accessed by means of reference-to-const, also because it wouldn't make much sense to "store const objects", for the same reason why a "vector<const int>" is meaningless. In our case, std::priority_queue uses std::less<> by default (as its Compare type), which provides a std::less::operator() declared as: bool operator()( const T& lhs, const T& rhs ) const; that in turn requires T (OP's "duty"..) to define operator< which *must* be const because it's called by a const member function. [If the OP had to define his/her type for a container like vector, operator< wouldn't be required to be const anymore]. > Theoretically you can use const_cast<> on the priority_queue top() > element to "remove const" and modify it and you should not run into any > problems as long as that change doesn't affect ordering. I understand that but that was not my point: a reference-to-const is a reference-to-non-const via const_cast<> as much as an int is a double via static_cast<>. -- Vincenzo Mercuri |
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Nov 28 01:53PM On 28/11/2014 02:24, Vincenzo Mercuri wrote: [snip] > I understand that but that was not my point: a reference-to-const > is a reference-to-non-const via const_cast<> as much as an int is > a double via static_cast<>. Wrong. The double would be a different object to the int when using static_cast<> whilst the result of the const_cast<> returns the *same* object. /Flibble |
bleachbot <bleachbot@httrack.com>: Nov 28 05:33AM +0100 |
ram@zedat.fu-berlin.de (Stefan Ram): Nov 28 01:29PM Someone writes: >Subject: Dealing with strings with NULL characters in the middle The ASCII character is spelled »NUL«. |
killet@killetsoft.de: Nov 27 11:05PM -0800 Here is a direct link to download a GeoDLL test version: http://www.killetsoft.de/zip/geodll.zip |
BV BV <bv8bv8bv8@gmail.com>: Nov 27 08:33PM -0800 Why is Smiling a Donation? (And smiling to your brother is donation). This is what the greatest Prophet (All Prayers and Peace of Allah be upon him) said and this is what the latest researches are discovering, so let's read .... Researchers have studied about smiling influence on others. They have found that smiling contains strong information that can influence the human subconscious mind! They found that everyone has his particular smile that no one can share with him. Moreover, every smile contains special effect, too. They photographed these smiles and showed it slowly, hence, they noticed some specific movements. Likewise, a person can have more than one kind of smiles, regarding his mental status, what is he speaking about and the person he is speaking to... Some of the most important information of such researches, researches are talking about what you can give to others through the smile, because it is more than giving a material thing for the following reasons: When smiling you can transmit joy to others, which is a sort of donation and which can be the most important. Studies showed that sometimes man may need joy and gladness more than food and drink. Also, that joy can treat many diseases starting by heart problems. Through the smile you can transmit information to others very easily, because a word with a smile has more influence on the brain. Magnetic resonance imaging has shown that expression influence changes too much with a smile. The expression is the same , however, the influenced brain parts differ according to smile type accompanying this information or this expression. You can calm an atmosphere stain of a given situation with a soft smile. This cannot be done with money. Hence, smile is worthier and more important than money. So, the less you can give to others is smile donation. Smile and recovery: Many doctors have noticed smile influence on recovery. Therefore, some researches declare that the doctor's smile is a part of the treatment! Then, giving a smile to your friend, your wife or your neighbor, you are giving them a free remedy prescription without feeling, and this is a kind of donation. For these reasons and others, smile is considered as a sort of donation, giving and generosity. And now dear reader, do you realize why did the prophet of compassion (All Prayers and Peace of Allah be upon him) say: (and smiling to your brother is donation)!! -------------------- By: Abduldaem Al-Kaheel www.kaheel7.com/eng http://www.kaheel7.com/eng/index.php/legislative-miracles/193-why-is-smiling-a-donation- Source: · Smile -- And The World Can Hear You, Even If You Hide, www.sciencedaily.com, Jan. 16, 2008. Thank you |
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page. To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com. |
No comments:
Post a Comment