--- Log opened Fri Jan 30 00:00:02 2015 |
00:22 | <@gnolam> | https://twitter.com/AquilaRift/status/560798847904284673 |
00:28 | | Derakon[AFK] is now known as Derakon |
02:03 | <&Derakon> | http://thecodelesscode.com/case/178 |
02:16 | < Reiv> | I guess that's one way to make an arguement |
02:21 | <@celticminstrel> | XD |
02:30 | | Thalass [thalass@Nightstar-h1qmno.eastlink.ca] has quit [Ping timeout: 121 seconds] |
03:00 | | Thalass [thalass@Nightstar-h1qmno.eastlink.ca] has joined #code |
03:00 | | mode/#code [+o Thalass] by ChanServ |
03:34 | | Thalass [thalass@Nightstar-h1qmno.eastlink.ca] has quit [[NS] Quit: slep] |
04:10 | | McMartin [mcmartin@Nightstar-rpcdbf.sntcca.sbcglobal.net] has joined #code |
04:10 | | mode/#code [+ao McMartin McMartin] by ChanServ |
04:34 | | Checkmate [Z@Nightstar-484uip.cust.comxnet.dk] has quit [Ping timeout: 121 seconds] |
04:45 | | sunwind [windsong@Nightstar-nie.4e0.225.105.IP] has joined #code |
04:45 | < sunwind> | hi |
04:46 | | sunwind [windsong@Nightstar-nie.4e0.225.105.IP] has quit [[NS] Quit: ] |
05:12 | | Turaiel is now known as Turaiel[Offline] |
05:23 | | Vornicus [vorn@ServerAdministrator.Nightstar.Net] has quit [[NS] Quit: Leaving] |
06:26 | < simon_> | heh. the cleaning guy at my uni dept. just picked up a bunch of coins and let them drop, so it'd seem like he paid for coffee. |
06:28 | | celticminstrel [celticminst@Nightstar-q7on2v.dsl.bell.ca] has quit [[NS] Quit: And lo! The computer falls into a deep sleep, to awake again some other day!] |
07:24 | | Kindamoody[zZz] is now known as Kindamoody |
08:00 | | Kindamoody is now known as Kindamoody|out |
08:03 | | Orthia [orthianz@Nightstar-32c.o7s.224.119.IP] has quit [Ping timeout: 121 seconds] |
08:08 | | gizmore [kvirc@Nightstar-5j63s3.pools.vodafone-ip.de] has joined #code |
08:09 | | Orthia [orthianz@Nightstar-hs6.78p.224.119.IP] has joined #code |
08:09 | | mode/#code [+o Orthia] by ChanServ |
09:54 | | Attilla [sid13723@Nightstar-ed0oqj.irccloud.com] has quit [[NS] Quit: ] |
09:54 | | Attilla [sid13723@Nightstar-h2b233.irccloud.com] has joined #code |
11:46 | | Xon [Xon@Nightstar-j72.ku7.252.119.IP] has quit [[NS] Quit: No Ping reply in 180 seconds.] |
11:49 | | Xon [Xon@Nightstar-j72.ku7.252.119.IP] has joined #code |
13:58 | | Alek [omegaboot@Nightstar-c8t.a00.36.73.IP] has quit [Ping timeout: 121 seconds] |
14:10 | <@Tarinaky> | Q: In C you have functions like printf which allow relatively painless string building with a format specifier and a list of data to insert into the string. |
14:10 | <@Tarinaky> | Is there an equivalent of this in C++? |
14:10 | <@Tarinaky> | stringstreams are a bit... awk... |
14:27 | < simon_> | stringstreams are foo << bar etc.? |
15:16 | | celticminstrel [celticminst@Nightstar-q7on2v.dsl.bell.ca] has joined #code |
15:16 | | mode/#code [+o celticminstrel] by ChanServ |
15:17 | | celticminstrel [celticminst@Nightstar-q7on2v.dsl.bell.ca] has quit [[NS] Quit: KABOOM! It seems that I have exploded. Please wait while I reinstall the universe.] |
15:18 | | celticminstrel [celticminst@Nightstar-q7on2v.dsl.bell.ca] has joined #code |
15:18 | | mode/#code [+o celticminstrel] by ChanServ |
15:46 | <&ToxicFrog> | Tarinaky: not as far as I know! |
16:31 | | himi [fow035@Nightstar-v37cpe.internode.on.net] has quit [Ping timeout: 121 seconds] |
16:39 | <@Tarinaky> | Basically I want something for building strings that behaves like Python's comp operator |
16:40 | <@Tarinaky> | C-string or Object accepteable. |
16:41 | <@Tarinaky> | I might have to throw something together with stringstream and a std::linkedlist :/ |
16:41 | <@Tarinaky> | No, wait, that won't work because I won't know what types are in the list. Argh. |
16:46 | <@celticminstrel> | You mean std::list? |
16:46 | <@celticminstrel> | Comp operator? |
16:47 | <@Wizard> | 15:10 <@Tarinaky> stringstreams are a bit... awk... |
16:47 | <@Wizard> | No, stringstreamers are C++ |
16:47 | | * celticminstrel is confused here. |
16:49 | <&ToxicFrog> | I believe the point is that C++ stringstreams are completely revolting compared to *printf |
16:49 | <@celticminstrel> | How so? |
16:49 | <@celticminstrel> | *printf is unsafe and not extensible. |
16:51 | <&ToxicFrog> | C: printf(" %4d %-60s\n", id, name); |
16:51 | <@celticminstrel> | Also ugly. |
16:51 | <@celticminstrel> | Though, I guess both ways are arguably ugly. |
16:53 | <&ToxicFrog> | C++: std::cout << " " << std::setw(4) << std::setfill(' ') << id << " " << std::setw(60) << std::setiosflags(std::ios::left) << name << std::endl; |
16:53 | <@celticminstrel> | Especially when considering field widths and stuff. |
16:53 | <@celticminstrel> | I thought there was a std::left or something so you don't need to use setiosflags. |
16:54 | <@celticminstrel> | Yup, there is. |
16:54 | <@celticminstrel> | So cout << " " << setw(4) << setfill(' ') << id << setw(60) << left << name << endl; |
16:56 | <@celticminstrel> | Oh, I missed the separating space. Meh. |
16:57 | <@celticminstrel> | So printf is compact, ugly, and unreadable, while C++ streams are verbose, ugly, and immediately understandable. |
16:58 | <@celticminstrel> | (Assuming people don't do things like setiosflags(12).) |
16:59 | <@celticminstrel> | Anyway, what is Tarinaky tryint to do here? |
17:00 | <@celticminstrel> | ^trying |
17:12 | <&ToxicFrog> | "immediately understandable" is really, really reaching. |
17:13 | <&ToxicFrog> | They're immediately understandable if you're already intimately familiar with them. |
17:13 | <&ToxicFrog> | Much like printf! |
17:13 | <&ToxicFrog> | But printf also has analogues in many other languages, so you're much more likely to already be intimately familiar with it. |
17:13 | <@celticminstrel> | "setw" and "setfill" are kinda more clear in meaning than "%4" |
17:13 | <&ToxicFrog> | And it makes it much easier to figure out what the output will look like, since the format is all in one place rather than scattered across half a dozen lines. |
17:14 | <@celticminstrel> | That's only really the case if you're only using "%d", "%s", etc. |
17:16 | <&ToxicFrog> | (also, printf has both a safe and portable subset, which includes basically all the parts you'd want to use regularly) |
17:17 | <@celticminstrel> | I suppose you can call it safe if your compiler supports checking format strings and you turn those warnings into errors. |
17:29 | | Checkmate [Z@Nightstar-484uip.cust.comxnet.dk] has joined #code |
17:42 | <&ToxicFrog> | celticminstrel: as it happens, it does and I do. |
17:43 | <&ToxicFrog> | To me the "unsafe" parts are any sprintf variant without 'n' in the name and the %n format |
18:03 | <@Tarinaky> | celticminstrel: No particular business domain problem. |
18:04 | <@Tarinaky> | I just think compact and ugly is better than verbose and ugly. |
18:05 | <@Tarinaky> | And would like a function in C++ that replicates the '%' operator on strings in python. |
18:06 | <@Tarinaky> | I think it's called comp but I might be wrong. |
18:06 | <@celticminstrel> | Oh. |
18:06 | <@celticminstrel> | But, how is the % operator different from (s)printf? |
18:07 | <@Tarinaky> | 1) It probably isn't as fully 'featured' and 2) It works on string assignment etc... printf writes to stdout. |
18:23 | <@celticminstrel> | I guess something like sprintf but for std::string instead of C-string? |
18:24 | <@Tarinaky> | That would work. |
18:25 | <@celticminstrel> | The problem with sprintf is that it might overflow buffers... and the problem with snprintf is that it might cut off if there's not enough space... |
18:26 | <@celticminstrel> | I'm not sure if you can calculate based on the format string and arguments exactly how much space will be needed. |
18:28 | <@Tarinaky> | Hmm, well... string arguments would be the same number of characters... integer types are just log10 of the integer, +1 if it's negative... |
18:28 | <@Tarinaky> | Not sure about floats. |
18:29 | <@celticminstrel> | The trouble is figuring out what types you have, I think. |
18:29 | <@Tarinaky> | How does sprintf do it? |
18:30 | <@celticminstrel> | By reading the format argument and assuming it's correct. |
18:30 | <@celticminstrel> | You could use variadic templates. It's confusing, though. |
18:31 | <@Tarinaky> | Easiest way to avoid overflow issues is to just build ontop of stringstream though and hide it. |
18:31 | <@celticminstrel> | Yeah. |
18:32 | <@Tarinaky> | Which leaves doing the parsing of the format string and a mechanism for passing in the parameters. |
18:32 | <@Tarinaky> | Since there's no variable length function arguments in C++ |
18:32 | <@Tarinaky> | Unless I'm missing something obvious and horrible. |
18:33 | <&ToxicFrog> | Tarinaky: I think what you want is boost::format |
18:33 | <@celticminstrel> | Assuming C++11, there's two ways, one of which is the C way. |
18:34 | <@Tarinaky> | ToxicFrog: That's looking right |
18:38 | <&ToxicFrog> | celticminstrel: as for what makes % different from snprintf, nothing really. It serves the same purpose. Has a few features snprintf doesn't, and of course since it's python the whole length calculation/string allocation nonsense is handled for you. |
18:39 | <&ToxicFrog> | celticminstrel: as for the length -- snprintf() returns the number of characters that would be written for that format string and arguments. |
18:40 | <@celticminstrel> | So if you call snprintf with a length of 0, you'll get the length required? |
18:40 | <&ToxicFrog> | Yes. |
18:40 | <&ToxicFrog> | It is in fact legal to call it with a null pointer and length of 0 to get the length, and then you can just allocate accordingly. |
18:41 | <&ToxicFrog> | Or you can pass in an existing buffer, and check afterwards to see if you got cut off and need to realloc and try again. |
19:03 | | Turaiel[Offline] is now known as Turaiel |
19:21 | < abudhabi> | Hahaha! |
19:21 | | * abudhabi manages to get his monitors to be as anoe. |
19:21 | < abudhabi> | *one |
19:24 | < abudhabi> | http://s1.bild.me/bilder/120914/5561939P1300254.JPG |
19:34 | <&jerith> | abudhabi: \o/ |
19:34 | <&jerith> | Won't the break in the middle be annoying, though? |
19:35 | < abudhabi> | It is a bit. |
19:36 | <&jerith> | Also, is that a realm stretching across all of Europe? |
19:36 | < abudhabi> | Yes. |
19:37 | <&jerith> | Mine's getting there. |
19:37 | <&jerith> | I still have about two and a half centuries to pick up the other half of the map. |
20:00 | | ErikMesoy is now known as Cyneric |
20:09 | | Kindamoody|out is now known as Kindamoody |
20:44 | <&ToxicFrog> | You can type-pun using luajit's FFI module! |
20:44 | <&ToxicFrog> | The luajit version of vstruct is going to fly. |
21:03 | <&McMartin> | That's one of the things FFI is good at |
21:04 | <&McMartin> | Older versions of the JVM had attributes you could set that meant the verifier was turned off and you could type-pun *those* too, it was great |
21:04 | <&ToxicFrog> | Awesome. |
21:04 | <&McMartin> | I don't think that was ever *actually specified* though. |
21:04 | <&ToxicFrog> | The #1 complaint about vstruct is that it's slow, so if I can provide an optional module that uses the FFI as a backend rather than wrangling all the bytes by hand... |
21:05 | <&McMartin> | (There's a flag that means "I was generated by the compiler to implement a language feature Java has and the JVM does not represent" and such functions were trusted implicitly) |
21:05 | <&McMartin> | (This is a bad design decision so I hope that's no longer true >_>) |
21:09 | | Checkmate [Z@Nightstar-484uip.cust.comxnet.dk] has quit [Ping timeout: 121 seconds] |
21:17 | <@celticminstrel> | The "synthetic" flag? |
21:18 | <&McMartin> | yep |
21:18 | <@celticminstrel> | What does type-pun mean? |
21:22 | <&McMartin> | reinterpret_cast<>(). |
21:22 | <@celticminstrel> | ...ah. |
21:45 | | thalass [thalass@Nightstar-h1qmno.eastlink.ca] has joined #code |
21:45 | | mode/#code [+o thalass] by ChanServ |
22:15 | | Checkmate [Z@Nightstar-pdi1tp.customer.tdc.net] has joined #code |
22:21 | | Turaiel is now known as Turaiel[Offline] |
22:22 | <&ToxicFrog> | celticminstrel: originally, the C version of it, where you do this: |
22:22 | <&ToxicFrog> | union pun { float f; uint32_t u; }; |
22:22 | <&ToxicFrog> | pun.f = myfloat; |
22:23 | <&ToxicFrog> | printf("%08X\n", pun.u); |
22:23 | <@celticminstrel> | Does the endian-checking thing count? |
22:24 | <@celticminstrel> | ie union {uint16_t x; uint8_t c;} endian; endian.x = 1; if(endian.c) ... |
22:24 | <&McMartin> | Probably, though that one also is making assumptions about padding. |
22:24 | <@celticminstrel> | Is that assumption something that could cause it to fail? |
22:25 | <&McMartin> | Not in any reasonable case, now that I sketch out the possibilities. |
22:26 | <@celticminstrel> | That's good, since that's how I'm checking for endianness. |
22:27 | <@celticminstrel> | (Which is needed because the legacy file formats were binary.) |
22:27 | <@celticminstrel> | (Well, I suppose the new ones are technically binary too, since they're gzipped.) |
22:28 | <&McMartin> | Basically, it would fail if you had the equivalent of #pragma(pack,2), which would put the uint8_t one byte to the right and thus get the answer backwards. |
22:29 | <@celticminstrel> | Maybe I should put the uint8_t first? |
22:29 | <&McMartin> | Er, wait, no, I have that backwards, n/m |
22:29 | | * McMartin is transitioning from low blood sugar to food coma over here |
22:29 | <&McMartin> | The traditional approach to this is to know in advance whether the architecture you're on is big-endian |
22:30 | <@celticminstrel> | Well, theoretically, this is here in case someone decides to compile this for PPC macs... which does sound rather unlikely though... |
22:31 | <@celticminstrel> | (Especially since I'm linking with 10.7 SDK.) |
22:31 | <&McMartin> | Right, but basically, when compiling for PPC some #define should be set that says YOU ARE BIG-ENDIAN, 100% OF THE TIME |
22:31 | <&McMartin> | And for x64, the other way around |
22:31 | <&McMartin> | The exciting one is ARM, which IIRC can switch at runtime |
22:31 | <@celticminstrel> | I see. |
22:31 | <&McMartin> | My preferred solution for serializing into these cases is to simply only read a byte at a time. |
22:32 | <&McMartin> | As long as the *format itself* is consistently big- or little-endian, it's pretty trivial to write read-loops that give the same answer on any archicture by combining bytes with shifts and ORs. |
22:33 | <@celticminstrel> | The reading code for legacy formats already works though, so I don't really feel like poking at it. |
23:03 | | Kindamoody|autojoin [Kindamoody@Nightstar-e0h756.mobileonline.telia.com] has joined #code |
23:03 | | mode/#code [+o Kindamoody|autojoin] by ChanServ |
23:03 | | Kindamoody [Kindamoody@Nightstar-e0h756.mobileonline.telia.com] has quit [Connection closed] |
23:04 | | Kindamoody|autojoin is now known as Kindamoody |
23:10 | | Kindamoody is now known as Kindamoody[zZz] |
23:46 | | Cyneric is now known as ErikMesoy |
23:49 | | celticminstrel [celticminst@Nightstar-q7on2v.dsl.bell.ca] has quit [Connection closed] |
23:52 | | celticminstrel [celticminst@Nightstar-q7on2v.dsl.bell.ca] has joined #code |
23:52 | | mode/#code [+o celticminstrel] by ChanServ |
--- Log closed Sat Jan 31 00:00:18 2015 |