« first day (1411 days earlier)      last day (3530 days later) » 

2:02 AM
sigh
printf("%x\n", my_unsigned_char); -> works fine
std::cout << std::hex << my_unsigned char; -> terrible
it prints the character instead
what's the point of the hex manipulator if they refuse to do anything about it
 
When in doubt, cast it!
oh wait
 
if I cast it to an int
I get ffffff[my byte]
which I don't want..
 
user3010322
 
Casting an unsigned char to int?
 
I just want to print the byte in hex
 
user3010322
2:05 AM
Waahhh, how does it work. ;~;
 
user3010322
 
you have a space
 
[meta-tag:status-by-design]
 
user3010322
There we go.
 
2:05 AM
22
Q: how do I print an unsigned char as hex in c++ using ostream?

Nathan FellmanI want to work with unsigned 8-bit variables in C++. Either unsigned char or uint8_t do the trick as far as the arithmetic is concerned (which is expected, since AFAIK uint8_t is just an alias for unsigned char, or so the debugger presents it. The problem is that if I print out the variables us...

 
@ThePhD Still fail. Not meta tag.
 
I think I'd like a Danish next
 
...
 
user3010322
@MarkGarcia I'm okay with a regular tag for now.
 
Well.
 
2:07 AM
@Rapptz cast it to unsigned int then
 
Your + actually did the trick.
Yeah the signedness messed me up
still, I just wanted to use the regular character :(
 
user1646075
holy crap just got front row tickets to rodriguez at sydney opera house. Gloating! Catch him before he dies
 
not cast it
bad iostreams
smacks with newspaper
 
I don't think it should do that for unsigned char, ideally. Only char.
But hey.
 
I think it shouldn't print the character if a manipulator is in place.
e.g. std::bin, std::hex
iunno
 
2:13 AM
I am still feeling a bit sick from the food poisoning so I am only have baked beans and boiled veges & mushroom for lunch today, no fresh red meat, eggs or seafood
 
Not fond of having more state.
 
You could use the standard but really wordy approach... std::cout << std::hex << std::char_traits<char>::to_int_type(c) << std::endl;
Obviously that's better than casting
 
Man, from my Google search history, there's no way Google would believe I'm a girl.
@HWalters lol
 
Lesbians exists.
 
oh you're still here
 
2:17 AM
Lesbian probably watch different kind of porn, also it's 'Lesbians exist.'
 
@Mysticial are intel cpus still write back? one would thing with QPI they would have considered a switch.
 
Oh holy shit
I was going through some of my old answers
and I just realized that tchrist replied to one of them
 
boost::demangle only accepts const char* :|
 
@OmnipotentEntity are you embarrassed yet?
 
ITT Kitty teaching Englishes
 
2:19 AM
Nah, just slightly star struck
 
only a select few girls shall be honoured with a space in my downloads folder
proceeds to 'Save As' 50,000 images
 
omfg, you preverted stalker!
^ that's the impression your webcam gave me
 
You're the one clicking on links posted by ladies in chatrooms labelled "My webcam"
 
you are a lady, yeah right ... maybe I could con people into believing my pet chicken were fire Phoenix too
 
@LucDanton It's not more state.
I don't see how it is.
 
2:31 AM
It kinda is
 
Before: I pass a character, a character is output; after: I pass a character, either a character or a number is output depending on bits
 
Huh?
It's depending on currently established manipulators.
 
Before & after your suggestion is implemented.
 
I don't see how this is different than true printing 1 or true depending if std::boolalpha is set.
 
It’s not different. It’s not desirable either.
 
2:32 AM
The user is the one who specified the flag.
 
19 mins ago, by Luc Danton
Not fond of having more state.
 
When I do std::cout << std::hex I'm explicitly requesting for the hexadecimal representation of whatever I'm passing.
 
That’s about the extent of my complaint. Don’t go looking for more.
 
I just don't see how it's 'more state' when the information is already available to the stream :|
 
It’s more bits to track in the programmer’s mind.
Obviously computers are very competent when it comes to handling stateful bits.
 
2:34 AM
It's not new state options, but it is more statefulness
 
It's an inconsistency.
 
Or, at least, it increases the size of the mapping of state to outcome
Because of the true/1 thing? Yes I would tend to agree
 
'Oh std::hex works on all integral types.. except unsigned/signed char.'
 
But I would say that the solution to that inconsistency is to remove the existing craziness, not add more
Well, char is not supposed to represent numbers, but characters. Kinda. So it's not that inconsistent.
 
(Also bool, speaking of.)
 
2:36 AM
Yeah
Otherwise you might as well claim that std::cout << 'o' outputting o is an "inconsistency", because it's no more one than your example
 
@Rapptz It is. I’m not sure where I would rank the need to solve it against my preference against state.
 
I'm guessing boost::formatdoes this properly? Since it follows *printf so well
 
nop
it just sets std::hex
someone else, @Mikhail, complained about it
because %d on a character printed the character not the numerical approximation
 
char, signed char, and unsigned char are distinct types in C++. The way I like to organize it in my brain is that char is a character; and signed/unsigned char are numbers.
So cout << c ideally should print characters if c is a char, ints if it's signed/unsigned
 
lol reminds me of uint8_t et al.
 
user1646075
2:40 AM
solution: borrow Stewie's time machine and give Dennis Richie a look down the retrospectoscope.
 
works fine if you treat them like normal numbers in printf , e.g. %d, but not on iostreams.
 
@Rapptz By the time printf sees them, chars (and shorts, for that matter) have already been promoted to ints.
 
yeah
but at least printf is consistent
 
Well yeah... int is the only type available
(In BCPL)
 
or well, more consistent than iostream anyway.
 
2:43 AM
@HWalters It’s true even when more types are available… so that’s irrelevant.
 
@Rapptz It's not really a matter of consistency as such. It's a matter of printf following whatever conversion specifier you pass it, regardless of the type of the object itself.
 
35 mins ago, by Lightness Races in Orbit
I don't think it should do that for unsigned char, ideally. Only char.
 
The matching problem, of course, is that it still tries to follow the conversion specifier, even if what you passed isn't of a type that matches it (e.g., the common printf("%d", 1.1);
 
@aclarke IRTA Denise Richards
 
@Mgetz I have no idea.
 
2:46 AM
@Mysticial thanks anyway, I know that intel was/is write back and AMD was/is write through... was explaining it to a friend that's in school and was curious if anyone knew anymore
 
That part of the cache never really had an important effect on performance.
At least not important enough for me to have to worry about it.
 
user1646075
Denise?
 
@Mysticial it does... but only on multithreaded corner cases that usually would have fences anyway due to the fact that vendors make no guarantees of cache coherency
 
user1646075
ohhhhh
 
user1646075
whatever IRTA stands for, I probably agree
 
2:48 AM
@Mgetz You have things backwards. Traditionally, AMD had write back and Intel did write through. I'm not sure about really current ones, but that remained true at least up through Sandy Bridge.
 
@JerryCoffin ah
 
@Mgetz For stuff that has a high rate of synchronization then I can see how it will matter.
 
at the end of the day it doesn't really matter, as for safety you'd have to do a full fence anyway
 
@Mysticial Also makes a substantial difference for the design of the cache snooping hardware. With write through, the lower-level caches are inclusive, so a cache snoop only needs to look at the lowest level cache to see of an item is on chip. With write back (and exclusive caching) you need to search all cache levels to know whether a cache snoop hit the chip.
Theoretically, write through doesn't have to equate to inclusive and write back to exclusive caching, but it is that way in all real chips of which I'm aware.
 
user3010322
2:54 AM
@Rapptz DLC...
 
user3010322
Heh.
 
$12 to double the size of the game :v
I'm all up for it.
 
@LucDanton: "It’s true even when more types are available… so that’s irrelevant" <- I think the opposite is true. It's true even when more types are available, because it's relevant...
 
@aclarke = I Read That As
goodnight ladies
 
2:58 AM
BCPL processed both "cells" with its single type, and characters. characters were kind of packed, but not addressable. BCPL took care of it with additional operators; e.g., use % to extract what we call a char from a vector; ! to extract what we call an int
 
I SAID GOODNIGHT BITCHES
 
user1646075
GOOD NIGHT, lezzo
 
user1646075
oh wait, you appreciate her style as a role model, right?
 
@LightnessRacesinOrbit it's 0300 get to sleep!
 
@LightnessRacesinOrbit not a dog, but night 2 u
ITT tomalak is still an attention whore ... who demands people to pay attention even as he goes to bed
 
it's only 2200.
In Texas.
I wish I wasn't in Texas.
 
@SamDeHaan it's 2108 here in denver, and I am about to go to bed
 
It's 1710 in Hawaii... wish I was in Hawaii
 
Yeah, I'm leaning towards sleep. Sitting in a sauna (un air conditioned warehouse) all day is tiring even if you don't move.
 
I thought you were in Michigan
 
3:15 AM
Yeah, but the job has travel. Horrible travel.
 
@SamDeHaan Travel to Texas? I agree-- it doesn't get much worse than that.
 
I mean, Ohio was pretty bad, but Texas in mid August is... rough.
 
Oh yes it does
 
@SamDeHaan Been there, done that, hope I never have to again. What part of Texas though? At least if it's not Houston, you can take that minimal comfort in the fact that it could be worse...
 
@HWalters ‘Irrelevant’ was perhaps a bad choice of adjective. I pointed out a discrepancy in the logic.
 
3:20 AM
is really warm in Texas @ moment, isn't it?
 
@JerryCoffin bit north of Dallas. The area is actually not that bad. I mean, the warehouse I'm working in has seen plenty of complaints for cat feces and fleas, but other than that and the 115°F mezzanine, it's not bad.
 
@chmod711telkitty Doing a quick check, this afternoon in Houston it was 34 degrees with 75% humidity.
@SamDeHaan Cat feces and fleas? What the hell kind of warehouse is this?
 
A warehouse for storing flea-infested cats.
You have to put them somewhere.
 
@LucDanton Presuming that's true, I nominate a lunar location.
 
We could put them next to the snakes.
Mare Anguis (the "serpent sea") is a lunar mare located on the near side of the Moon, about 150 kilometers in diameter. Located within the Crisium basin, Mare Anguis is a part of the Nectarian System, meaning that it was formed during the Nectarian time period. Like most mare, the surface of Mare Anguis is dark, indicating that it has been filled with volcanic basalt. == References... ==
 
3:27 AM
Here in San Diego, the weather was pretty rough today--hit a whopping 25 this afternoon, and just now (2030) down to my preferred 23. Supposed to get all the way down to 21 tonight--might have to break out my winter coat. :-)
@LucDanton Snakes, cats, and fleas. Sounds like a good combination to me.
 
@JerryCoffin A Home goods chain store with a feral cat problem, obviously.
I have yet to actually meet the cats, but their handiwork is not cleaned up as regularly as I would personally apprreciate.
 
3:42 AM
@SamDeHaan The next time I see my company owner, I may have to make a point to tell him how much I love my job and appreciate working here. :-)
 
I will do that regularly in my next job.
 
4:11 AM
feels like it
but it looks fun
 
user1646075
i would be inclined to say no, on the grounds of the C compatibility rules go to great lengths to let that kind of old-school stuff continue working
 
user1646075
but i ain't a language lawyer
 
@Rapptz Nope.
 
neat
standard-layout strikes again
 
user1646075
POD
 
4:15 AM
Initial common subsequence.
 
If I add a member function is it UB then?
 
user1646075
oh yeah! well done
 
I don't know how far the rabbit hole goes.
 
@Rapptz Not necessarily.
Unless you meant calling it as well, then yeah that’s bad (assuming non-static).
 
I meant
if test had a member function could I cast it to other*?
assuming the layout is the same otherwise
 
4:17 AM
Yes. You can always convert pointers. (Haha, this isn’t what you wanted right?)
 
user1646075
non-virtual of course
 
yeah non-virtual
 
user1646075
then .... i think virtualness is where the gates of hell start to open
 
for the curious, I'm wrapping up SDL_Rect but would like a way to turn my wrapped struct into SDL_Rect* so it works with the SDL calls.
 
Alright, I’ll look it up.
 
I meant the exact rules at play.
 
ah
 
user1646075
just curious - did the -Wall inspire any warnings?
 
nope
 
user1646075
/me forgets if the casts are totally immune to warnings even if you ask nicely...
 
4:21 AM
Ah, it’s ‘common initial sequence/part’.
 
user1646075
so a struct full of non-virtual functions will be cool in general?
 
user1646075
also curious - why can't you just pluck the sub-object as you pass it into the calls?

SDL_thingy(wrapper.sub_rect)
 
user1646075
with our without the & as per...
 
I could
but that's ugly
:p
 
user1646075
but ,......
 
4:23 AM
so I wanna do something uglier.
 
user1646075
heh
 
it doesn't help that the only things I find online are about C, not C++.
 
user1646075
not fair to call something fugly when it's, like, stating the truth
 
dubbed infomercials, so bad.
 
Welp, that’s worrying. The rules seem to only apply to accessing variant members (e.g. in a union). I’m not sure they cover pointers, so we may have been breaking aliasing all along.
 
user3010322
4:26 AM
Would it be fine under a reinterpret_cast of the pointer?
 
The nagging child, clang, doesn't emit any warnings with -Wall and -Weverything.
Interesting
 
user1646075
reinterp is mostly about saying 'back the f*ck off, I know what I'm doing' isn't it? but if you don't ........
 
Well I lied
It did emit one warning.
main.cpp:19:2: warning: C++98 requires newline at end of file [-Wc++98-compat-pedantic]
 
How horrifying.
 
@LucDanton I found an answer on SO that said it's okay in C. But that doesn't have to translate well in C++ unfortunately.
 
4:29 AM
Yup. That may explain why I remember the rule as applying here.
 
I think I may have found it.
8
Q: Safety of casting between pointers of two identical classes?

ClairvoireLet's say I have two different classes, both represent 2D coordinate data in the same internal way like the following: class LibA_Vertex{ public: // ... constructors and various methods, operator overloads float x, y }; class LibB_Vertex{ public: // ... same usage and intern...

 
Eh, the aliasing rules have no provision at all that seem to apply.
@Rapptz Using the pointer still breaks aliasing.
 
@Rapptz It's defined in C++. Oddly, in C89 it's technically undefined--but if you move one of the struct definitions to a different translation unit, then it becomes defined!
 
why would you convert to a pointer and then not use it though?
 
@JerryCoffin I would gladly welcome help tracking a reference.
@Rapptz There are many rules that govern pointers and guarantee you things. Mostly about roundtripping and so on.
I’m not saying it’s typical to have useless guarantees, but…
 
4:33 AM
time to dust out the ol' C++11 standard.
 
I also don’t understand the bullet point on aggregates when it comes to aliasing… it seems to allow aliasing an int through struct wat { double d; int i; }; but that’s just ludicrous.
 
@LucDanton §9.2/20. The "and vice versa" and the fact that they're both standard layout are crucial.
 
I found this.
last few sentences of § 3.9.2/3.
a bit too long
> Pointers to cv-qualified and cv-unqualified versions (3.9.3) of layout-compatible
types shall have the same value representation and alignment requirements (3.11).
and it goes on to mention over-aligned types
 
@JerryCoffin It stops at §19 for me—in any case I’m looking for a way out of the aliasing rules: sure we have the pointer, but what can we do with it?
@Rapptz That’s the SO answer above.
 
This is from N3337: "A pointer to a standard-layout struct object, suitably converted using a reinterpret_cast, points to its
initial member (or if that member is a bit-field, then to the unit in which it resides) and vice versa."
 
4:36 AM
@LucDanton Oh. I suck.
4
 
@JerryCoffin …which is a fairly important paragraph, or so I thought—where did it go in the later versions?
Oh I’ve seen the non-normative note, so maybe they shuffled things around a bit.
 
I suppose to mean much, you also need 9.2/17: "Two standard-layout struct (Clause 9) types are layout-compatible if they have the same number of non-static
data members and corresponding non-static data members (in declaration order) have layout-compatible
types (3.9)."
 
@JerryCoffin I have that paragraph too.
It's §19 though.
N3376.
 
Small question: Is it necessary to do: return foo(std::move(obj));
Or is return foo(obj); good enough.
 
@Mysticial yes
 
4:39 AM
@LucDanton Looking now. Doesn't seem to be anywhere in quite the same form (in N3797).
 
@Mysticial no
 
"A pointer to a standard-layout struct object, suitably converted using a reinterpret_cast, points to its initial member (or if that member is a bit-field, then to the unit in which it resides) and vice versa." - ISO 14882-2011[2012], quoted, small sample, edification, fair use, etc etc
 
I don’t question that the resulting pointer is sane. But the only exception to aliasing rules regarding layout-compatible types I see is for unions.
@JerryCoffin Ah it’s okay I’ve seen it earlier.
 
foo(std::move(obj)) invoked the move constructor, foo(obj) does copy constructor.
 
@Rapptz thanks! I know that return directly doesn't require std::move(), but I wasn't sure about passing it through an expression.
 
4:40 AM
...to answer the question about "later versions"
 
@Mysticial I was sure I read that as return std::move(foo(obj)) which isn't also good enough.
 
I have the C++14 ISO standard
I could check if it's still there
 
It’s §17 in the latest.
(Also I’m fairly sure I’m not in the mood to dive into the C drafts tonight so I won’t be checking the rules there.)
 
Actually, is the compiler even allowed to convert copies to moves if it is able to determine that the value is not needed afterward?
 
@LucDanton It's something else in the ISO C++14 standard.
 
4:44 AM
i.e. copy-elision for moves.
 
…didn’t they say they were only minor changes relative to the latest drafts? :s That was n39xx.
 
user3010322
They lie.
 
@Mysticial Except for return, no AFAIK.
 
user3010322
They always lie.
 
@Mysticial Nope (barring as-if etc.).
 
4:44 AM
I don't see that reinterpret_cast paragraph in the ISO C++14 standard :s
 
@LucDanton Ah. So it's not like constructor copy-elision where the standard allows it even if it changes the result.
 
@Rapptz I wasn’t referring to the pointer casting, but layout-compatibility.
 
Also, return is well-defined to move, with all the xvalues/prvalues and stuff.
 
@Mysticial That’s right.
 
> Two standard-layout union (Clause 9) types are layout-compatible if they have the same number of nonstatic data members and corresponding non-static data members (in any order) have layout-compatible types (3.9).
That's p. 17
 
4:46 AM
:)
 
@MarkGarcia I believe there are a few other cases (e.g., a throw expression) but not ones you typically care much about.
 
so is it UB in C++14 then?
 
@JerryCoffin Which of course VS2013 is wrong and they closed it as by-design.
 
@Rapptz (And before.) IIRC the allowance for unions is the closest to standardizing type-punning via unions.
 
You cannot throw move-only objects in VS2013 because their interpretation of the standard is that they can't.
 
4:49 AM
They interpret the ISO MSVC standard.
 
But what about paragraph 19?
 
k I’ve scoured all the mentions of standard-layout and layout-compatible and there isn’t anything that we haven’t mentioned. Hopefully there isn’t some hyphen trickery that means I’ve missed something :s
 
aw
that's no fun
 
@Rapptz That was a misunderstanding (a stale reference was read ;).
 
I mean, it works in practice but still sad
 
4:50 AM
@Mysticial I think they're probably right--while the compiler is allowed to elide the copy/move, it's not required to do so, and is supposed to check for the existence of the correct copy ctor even if it elides the copy (or converts it to a move). I'd have to check the details to be sure though.
 
A part of me still thinks it's valid.
 
Eh, strict aliasing is very important for optimizations (or so the compiler writers tell me).
 
You can't really trust VS2013 on anything involving move semantics though.
 
I have no way of turning things to a pointer using a union
so it's not that fun for me
or helpful
@LucDanton Adobe Reader interprets a b to match both a b and a-b.
 
Mmmh, can layout-compatible types be bit-blasted from one form to the other? I think it should be allowed, but I doubt it is.
 
4:54 AM
what if I use std::align?
:v
 
wtf all my documents so far were nXXXX but the draft is NXXXX
 
@Rapptz You could run out of space.
 
> This International Standard specifies only two ways of obtaining such a pointer: taking the address of a valid object with an over-aligned type, and using one of the runtime pointer alignment functions.
 
@Rapptz Not what I’m using.
 
@LucDanton If and only if they're standard layout (at least IIRC).
 
4:55 AM
Adobe Reader is great!
 
@Rapptz The pointer is already proper.
 
Where does it explicitly/implicitly disallow the use of the proper pointer?
 
Strict aliasing is §3.10/10.
 
Well
Now I don't know how to solve my problem.
There goes my bronze bullet.
 
@Rapptz What's your real problem?
 
4:59 AM
Can you embed the original type inside?
 

« first day (1411 days earlier)      last day (3530 days later) »