- escape sequence '\(' - 7 Updates
- XKCD: I hate reading your code - 1 Update
- NEWBIE question: Is this a bug in my compiler? - 1 Update
- NEWBIE question: Is this a bug in my compiler? - 1 Update
- A new algorithm of an efficient Threadpool engine that scales well - 3 Updates
- About C++ style (functions) - 1 Update
- std::reverse_iterator Confusion - 3 Updates
- is the brackets ([]) the comment symbols ? - 5 Updates
- operator == on vectors - 2 Updates
- boost::regex_relace vs. std::regex_replace: Who is right? - 1 Update
Ralf Goertz <me@myprovider.invalid>: Jun 22 03:47PM +0200 What is the following warning given by g++ supposed to mean? es_test.cc:6:32: warning: unknown escape sequence: '\)' std::string legal="\(",illegal="\)"; ^ In particular, if '\(' is a known escape sequence (for what?) why isn't '\)'? |
Christian Gollwitzer <auriocus@gmx.de>: Jun 22 04:10PM +0200 Am 22.06.16 um 15:47 schrieb Ralf Goertz: > es_test.cc:6:32: warning: unknown escape sequence: '\)' > std::string legal="\(",illegal="\)"; > ^ In general, you should double all literal backslashes in a string, in order not to fall for something like "C:\newstuff" which gets interpreted as a newline character. The backslash is treated as a literal backslash if the character that follows does not give a vald escape sequence; but even if it des not now, a future compiler miht treat it differently. > In particular, if '\(' is a known escape sequence (for what?) why isn't > '\)'? I don't know, but since you intend to write literal backslashes, you should write it as "\\(" and "\\)" Christian |
Ralf Goertz <me@myprovider.invalid>: Jun 22 05:00PM +0200 Am Wed, 22 Jun 2016 16:10:36 +0200 > > isn't '\)'? > I don't know, but since you intend to write literal backslashes, you > should write it as "\\(" and "\\)" No, I don't intend to write that. I came across that warning when I accidentally omitted one backslash trying to write "\\\\)". I experimented and discovered that "\(" didn't give the warning. Since I had never seen the escape sequence '\(' I looked it up in the standard. But there I only found: "Escape sequences in which the character following the backslash is not listed in Table 7 are conditionally-supported, with implementation-defined semantics." Table 7 doesn't list '\('. So I figured gcc might have defined it. But I found nothing in the man pages. That's why I asked. |
guinness.tony@gmail.com: Jun 22 09:19AM -0700 On Wednesday, 22 June 2016 14:47:34 UTC+1, Ralf Goertz wrote: > ^ > In particular, if '\(' is a known escape sequence (for what?) why isn't > '\)'? '\(' isn't a known escape sequence and, as such, should be just as "illegal" as '\)'. The question really should be "why does g++ accept this non-standard escape sequence?". Which, of course, only the authors, documentation and/or source code comments of g++ can tell you. Out of interest, I've tested for other such undocumented escape sequences. Apart from the "legal" ones (as defined by The Standard), g++ also recognises '\%', '\(', '\[' and '\{', which all translate to their unescaped versions. Additionally, it recognises '\E' and '\e', translating both to ASCII <ESC>. |
legalize+jeeves@mail.xmission.com (Richard): Jun 22 05:41PM [Please do not mail me a copy of your followup] Christian Gollwitzer <auriocus@gmx.de> spake the secret code >> std::string legal="\(",illegal="\)"; >> ^ >In general, you should double all literal backslashes in a string, Good god, no. Just use raw string literals. C++11, ya know. It's already 5 years old. -- "The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline> The Computer Graphics Museum <http://computergraphicsmuseum.org> The Terminals Wiki <http://terminals.classiccmp.org> Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com> |
legalize+jeeves@mail.xmission.com (Richard): Jun 22 05:43PM [Please do not mail me a copy of your followup] Ralf Goertz <me@myprovider.invalid> spake the secret code >No, I don't intend to write that. I came across that warning when I >accidentally omitted one backslash trying to write "\\\\)". VS 2015 can refactor such string literals to raw string literals and I added a similar check to clang-tidy: <http://clang.llvm.org/extra/clang-tidy/checks/modernize-raw-string-literal.html> -- "The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline> The Computer Graphics Museum <http://computergraphicsmuseum.org> The Terminals Wiki <http://terminals.classiccmp.org> Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com> |
Victor Bazarov <v.bazarov@comcast.invalid>: Jun 22 01:51PM -0400 On 6/22/2016 1:41 PM, Richard wrote: >[..] > C++11, ya know. It's already 5 years old. Can you trust a 5-year-old with your stuff? ;-) V -- I do not respond to top-posted replies, please don't ask |
Wouter van Ooijen <wouter@voti.nl>: Jun 22 06:47PM +0200 Op 21-Jun-16 om 9:21 PM schreef Stefan Ram: > Then make that > char* p, > q; ROFL! Wouter |
ram@zedat.fu-berlin.de (Stefan Ram): Jun 22 03:16PM >cout << func(x) << " " << x << endl; C++ does not specify the order of the evaluation (the »sequencing«) of the operands of the operator »<<«. So, one implementation can legally evaluate »func( x )« before »x«, while another implementation can legally evaluate »x« before »func( x )«. You can rewrite this as int const a = func( x ); int const b = x; ::std::cout << a << " " << b << '\n'; or int const b = x; int const a = func( x ); ::std::cout << a << " " << b << '\n'; to have it deterministically the one way or the other. Or maybe to cout << func(x) << " "; cout << x << endl; if that was what you wanted. |
mehrdad ghassempoory <m-ghassempoory@ntlworld.com>: Jun 22 04:07PM +0100 I have a very simple program shown below, I use gnu c++ version 4.8.4. I expect the program to print: 0 2 but I get 0 0 however, if I use clang++ version 3.5, I get what I expected: 0 2 Is this a bug in gnu c++ or maybe I am confused about the way << operator works? ++++++++++++++++++++++++++++++++++++++++++++++++++ #include <iostream> using namespace std; int func(int& x) { x=2; return 0; } int main() { int x; x=0; cout << func(x) << " " << x << endl; return 0; } --------------------------------------------------- |
Mr Flibble <flibble@i42.co.uk>: Jun 22 12:54AM +0100 On 21/06/2016 23:07, DecadentLinuxUserNumeroUno wrote: >> crap here. > then why not translate it in C++ or C if you have some brains to do so. > Don't talk crap here - fucker. Oh look, we have a new little fucktard make a post. Why would I, mate, want to translate some random spammer's Pascal source code into C++? You are in serious need of a clue. /Flibble |
Ian Collins <ian-news@hotmail.com>: Jun 22 04:11PM +1200 On 06/22/16 09:04 AM, Mr Flibble wrote: <stuff that won't change anything> Please don't respond to (and even worse quote) Ramine spam news servers filter out! -- Ian |
Mr Flibble <flibble@i42.co.uk>: Jun 21 10:04PM +0100 On 21/06/2016 21:35, Ramine wrote: > You can download my efficient Threadpool engine version 3.0 that scales > well from: > https://sites.google.com/site/aminer68/an-efficient-threadpool-engine-that-scales-well This is a C++ newsgroup not a Pascal newsgroup so stop posting Pascal crap here. /Flibble |
Stanimir Stamenkov <s7an10@netscape.net>: Jun 18 01:52AM +0300 Mon, 6 Jun 2016 08:42:02 -0400, /Jerry Stuckle/: > Yes, by not following the RFC's and then complaining about others, you > are behaving as an asshole. > See https://www.ietf.org/rfc/rfc3676.txt section 4.3. This doesn't mandate everyone should use this signature separator. It has its uses mainly for signatures which include more than simple name, and spread two or more lines. One may sign using any of: - Name /Name -- Name or another style. I think you're just being rude, lazy, or just ignorant by not stripping it yourself (if the reader doesn't or can't do it automatically for you), just like you should trim quotes to a sane minimum, and that can't be automatic. -- Stanimir |
MikeCopeland <mrc2323@cox.net>: Jun 17 11:02AM -0700 I'm confused about string::reverse_iterator usage. What I'm trying to do is scan the end of a string variable for all numeric digits..and then convert those digits to an integer. For example, I have; std::string myData = "cldat89"; and I want to extract and convert the "89" to an integer variable. Various explanations I've found via Google aren't making sense to me, as they mostly assume I want to reverse the whole string data or such. I just want to scan backwards (from last-to-first) until a character _isn't_ a digit...and then be able to work with the substring of the digit characters. Although done this task "brute-force", the concept of reverse_iterator seemed interesting, so I wanted to try it: so far, I don't "get it". Please advise. TIA --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus |
Victor Bazarov <v.bazarov@comcast.invalid>: Jun 17 02:29PM -0400 On 6/17/2016 2:02 PM, MikeCopeland wrote: > Although done this task "brute-force", the concept of > reverse_iterator seemed interesting, so I wanted to try it: so far, I > don't "get it". Please advise. TIA When you "scan backwards", remember that the characters come in the reverse order. So, something like this is supposed to work: int accumulator(0); int multiplier(1), maxnumber(100000); std::locale defloc; for (auto it = myData.rbegin(); it != myData.rend() && multiplier < maxnumber; ++it, multiplier *= 10) { char c = *it; if (std::isdigit(c, defloc)) accumulator += (c - '0') * multiplier; else break; } (I didn't actually test this, but it should give you an idea). V -- I do not respond to top-posted replies, please don't ask |
legalize+jeeves@mail.xmission.com (Richard): Jun 17 06:23PM [Please do not mail me a copy of your followup] MikeCopeland <mrc2323@cox.net> spake the secret code > std::string myData = "cldat89"; >and I want to extract and convert the "89" to an integer variable. A reverse iterator is not needed: 1 #include <iostream> 2 #include <string> 3 4 int main() 5 { 6 std::string s{"cldata89"}; 7 auto pos = s.find_last_not_of("0123456789"); 8 int val = std::stoi(s.substr(pos + 1)); 9 std::cout << val << '\n'; 10 return 0; 11 } > g++ --std=c++11 /tmp/a.cpp > ./a.out 89 However, for the purposes of education, a reverse iterator simply traverses a container in the opposite order of a forward iterator. I think cppreference.com does a good job of explaining it: <http://en.cppreference.com/w/cpp/iterator/reverse_iterator> -- "The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline> The Computer Graphics Museum <http://computergraphicsmuseum.org> The Terminals Wiki <http://terminals.classiccmp.org> Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com> |
David Brown <david.brown@hesbynett.no>: Jun 17 09:51AM +0200 >> So, the question is, does the man wrong, or i did something wrong ? > Here is what that man said: > a[5] is the same as 5[a] True (within the right context). But that was considered an unfortunate quirk of the language and very bad style 20 years ago when this thread was started - it is even more so now. It is good to be helpful and try to answer questions on Usenet, but I doubt that the OP here has been holding his breath for the last two decades, waiting for an answer! |
Robert Wessel <robertwessel2@yahoo.com>: Jun 16 11:29PM -0500 >> So, the question is, does the man wrong, or i did something wrong ? >Here is what that man said: >a[5] is the same as 5[a] It's not true for declarations, so "int 10[a]" doesn't work. OTOH, when you access an array, you can write: a[10] = 3; -or- 10[a] = 3; and accomplish the same thing. That's because the array accessor essentially decays into a pointer expression. IOW, the two above lines are equivalent to: *(a+10) = 3; -and- *(10+a) = 3; The later form ("10[a]") is primarily used to confuse newbies. But it's in no way a comment. |
Real Troll <real.troll@trolls.com>: Jun 17 06:21PM +0100 On 17/06/2016 08:51, David Brown wrote: > It is good to be helpful and try to answer questions on Usenet, but I > doubt that the OP here has been holding his breath for the last two > decades, waiting for an answer! He must have died by now!!!!!!!!!! |
Ian Collins <ian-news@hotmail.com>: Jun 17 10:47PM +1200 > On Friday, December 12, 1997 at 12:00:00 AM UTC-8, Alexey Maykov wrote: Time travel again... -- Ian |
legalize+jeeves@mail.xmission.com (Richard): Jun 17 05:35PM [Please do not mail me a copy of your followup] As others have already mentioned swapping the name of an array and it's index may be valid syntax, but it is not recommended. Just because something is allowed doesn't mean it's a good idea. maykov@gmail.com spake the secret code >Here is what that man said: >a[5] is the same as 5[a] For expressions in the C language, yes. 1 #include <stdio.h> 2 3 int main() 4 { 5 int a[1] = { 0 }; 6 0[a] = 10; 7 printf("%d\n", a[0]); 8 return 0; 9 } > gcc /tmp/a.c > ./a.out 10 For expressions in the C++ language, no. 1 #include <iostream> 2 #include <vector> 3 4 int main() 5 { 6 std::vector<int> a(1); 7 0[a] = 10; 8 std::cout << a[0] << '\n'; 9 return 0; 10 } > g++ /tmp/a.cpp -o a2.out /tmp/a.cpp: In function 'int main()': /tmp/a.cpp:7:4: error: no match for 'operator[]' (operand types are 'int' and 'std::vector<int>') 0[a] = 10; ^ -- "The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline> The Computer Graphics Museum <http://computergraphicsmuseum.org> The Terminals Wiki <http://terminals.classiccmp.org> Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com> |
Jorgen Grahn <grahn+nntp@snipabacken.se>: Jun 16 02:42AM On Tue, 2016-06-14, Wouter van Ooijen wrote: [ÖT] > contains a verb like is, has, contains, includes, etc. > The other function (the one that makes something empty) should probably > be called make_empty(). But still, the C++ containers have a different convention: bool empty() const; void clear(); For better or worse, I've adopted that convention. If I write a container-like class and need that feature, I'll use those names. I probably would even if I objected to them more than I do. /Jorgen -- // Jorgen Grahn <grahn@ Oo o. . . \X/ snipabacken.se> O o . |
Jorgen Grahn <grahn+nntp@snipabacken.se>: Jun 16 02:32AM On Tue, 2016-06-14, 嘱 Tiib wrote: > What is correct by those "conventions"? Is it 'vector::get_allocator()' or > 'vector::allocator()'? Is it 'vector::capacity()' or 'vector::get_capacity()'? > Feels there are no such "conventions". Let's say "in line with the /lack/ of naming conventions", then. > programming language therefore usage of word that is both verb and > adjective ('empty') for function name in meaning of that adjective is > misleading. Frank way of naming such function would be 'is_empty'. There doesn't seem to be a lot of is_adjective() in the standard library, though. Except in <type_traits>. ... > if (foobar.size() != 0) ... // the reality > I suspect that it is so (at least partially) because 'empty' is such a > bad name. ;-) I think that if people write such code, it's because they usually want the negation -- my "hard to spot the !" argument. I don't think I've seen size() used that way. Maybe I've been lucky. I have sometimes been tempted to write such code myself, but after an incident with std::list (where size() at least /might/ be O(n)) I hesitate to ask for more information than I'm really going to need. /Jorgen -- // Jorgen Grahn <grahn@ Oo o. . . \X/ snipabacken.se> O o . |
Ralf Goertz <me@myprovider.invalid>: Jun 22 09:56AM +0200 Am Tue, 21 Jun 2016 09:19:16 -0700 (PDT) > be platform-neutral so usually there will be several > platform-specific implementation after something of it is > standardized. I am well aware of boost's role in the advancement of the standard. Of course there can be modifications during that process. That is one of the reasons why I try to get rid of boost functions as soon as there are std alternatives. Not that I don't like boost. On the contrary, I am very grateful for the work of its programmers. > I have also read gossip that boost had some Perl-like features to that > "ECMAScript" that std::regex is not required to contain but i'm > unsure if it is about those backslashes. It seems I hadn't looked hard enough. Boost clearly states that the backslash is an escape character in all three variants of the format string (Sed, Perl, Boost-Extended). What puzzled me was that it is also (and in the Sed-case only) used for the `normal' escape sequences like '\t' which means that the string literals "\t" and "\\t" give the same result in boost::regex_replace when used as a replacement (format) string. > actually does. These two things are never exactly same and also both > documentation and behavior will change over time. Also, what problem > needs usage of both boost::regex and std::regex in mix? None of course. But as I said in my initial post I am switching from boost::regex to std::regex now that my upgrading gcc made the latter available. During that process I discovered the problem. |
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