« first day (1454 days earlier)      last day (3497 days later) » 

cpx
7:00 AM
Why does this sizeof thing works with stl strings?
 
So I'm looking at some code I wrote more than 3 years ago. And I can't read it, nor do I remember what I did...
shit
 
cpx
I've only used it with integer arrays.
 
@cpx Well it's still an array.
 
cpx
With ints it returns the size of datatype, but it seems with strings it's returning the size of value.
 
Wat? No! sizeof still returns the size of std::string (in that case).
 
cpx
7:04 AM
I don't get the division part too.. since the length of each string is different.
 
sizeof(array) == sizeof(array[0]) * number of elements in array
so sizeof(array) / sizeof(array[0]) == number of elements.
 
only works with compile-time length arrays
 
> You can not even imaging
lol
 
Xeo
@StackedCrooked You slow!
 
7:12 AM
@Sofffia BTW, why are you reading that stuff?
 
cpx
In that case:
"sizeof(array) is 12"
"sizeof(array[0]) is 4"
work!
 
@MarkGarcia because reddit
and then I searched for more informations
and ended there
 
user1804599
 
cpx
where does these sizes come from?
 
Size is an intrinsic property of an object type. That’s what you’re seeing.
 
7:15 AM
12 bytes for a pointer?
holy tits
 
Xeo
wat
 
I'm assuming array is a pointer
When in reality it's a T[]
 
cpx
That is my array: std::string array[] = {"One", "Two", "Three"};
 
@rightføld I don't understand...
 
Yeah, nevermind me. I'm being silly.
 
user1804599
7:16 AM
@MarkGarcia It shows the values of variables next to the code while debugging.
 
@rightføld Oh. The todos: Array[2] in the screenshot looks like a comment.
@Sofffia I was afraid of you there for a second.
 
user1804599
Comments start with //, /* or <!--, silly.
 
But when you see todo: highlighted just like a comment... So just realized I cannot live without syntax colorization anymore.
 
user1804599
Werkzeug's debugger is a great thing though.
 
cpx
So, how come sizeof all elements is 4? This doesn't make sense.
 
user1804599
7:22 AM
When you get an error you are presented with a stack trace and you get a Python REPL for each stack frame individually.
 
user1804599
@cpx why not? std::string happens to be 4 bytes in size there.
 
@cpx std::string might be implemented as a pointer to a dynamically allocated array of chars.
 
cpx
The third element has more characters in it than first and second elements.
 
who cares damnit
 
@cpx Of course it makes sense. It might not meet your expectations, but there's always documentation to correct that
 
7:24 AM
implementation defined stuff is boring
 
@cpx (hint: we noticed).
 
cpx
I see.
 
padding doesn't kick in probably because array
 
cpx
Since the memory of an array is contiguous blah blah so, I guess it's something to do with implementation.
 
user1804599
std::string may be just a pointer and some meta information.
 
7:28 AM
@rightføld that's likely exactly the point: sizeof(void*)==4 likely
 
@sehe You do know Clang in that case just uses the same std::string as GCC?
And it's quite a big difference :-o
 
cpx
After seeing this I can be sure it's a pointer of size 8 bytes :P
 
Yeah, an empty page often makes you realize the strangest things.
Oh it's not blank.
 
cpx
Haha, yes it just loaded for me too.
 
But libstdc++ might just be doing a pimpl string
and libc++ the sso
 
7:37 AM
@rubenvb Start pointer, size pointer/size, capacity pointer/size. GCC's cheating with its shared string implementation.
 
@MarkGarcia "shared string implementation"? What's that?
 
The reference counting string implementation.
Don't know what they formally call it.
 
I thought shared string implementation were an illegal implementation
 
user1804599
Anyone here hosts on Digital Ocean?
 
@Sofffia Yes it is. But they still do use it. :(
 
7:39 AM
@rightføld Github student pack?
 
user1804599
What is that?
 
@rubenvb you know that ABI plays into this too. But yeah, point taken
 
user1804599
@Sofffia It's not really relevant. :v
 
@cpx Yup.
 
cpx
7:40 AM
Okay, now I remember a quote from documentation.. If sizeof is used on an array then it triggers array to pointer conversion.
 
@rightføld Yes, because if you are student (which I just realized you are not), then you can try it for free by yourself.
@cpx wat
 
user1804599
The company I work for is not a student. :v
 
@cpx actually, now you can
 
1 min ago, by Sofffia
@cpx Yup.
I like how you aligned the 8 like I did
 
@cpx nope. not if it's a lvalue
@Sofffia that's what you get for nondescript hyperlink anchors
 
7:43 AM
Says the "now" guy.
 
user1804599
@cpx no it does not
 
Ugh. Skype file download consuming too much CPU.
 
@Sofffia OT (Yes. "Yup" means nothing more than "Yes" (needs no hyperlink). "Actually, now you can" clearly suggests that the link shows additional information :))
 
@sehe My "Yes." is a reply to something he stated, which clearly shows additional information regarding that statement. BOOYAH.
 
@sehe ABI is the same... Clang is compatible with GCC (or tries to be).
@Sofffia That has been linked about four times now...
 
cpx
7:48 AM
@rightføld oh right (§ 5.3.3/4) - No array to pointer conversion is applied to operand of sizeof.
It returns the size of entire array in bytes.
 
user1804599
Yes.
 
@cpx Bingo!
 
One can actually argue that C++-style casts should be reserved for hierarchical pointer casts and various hack-casts, while classic C-style casts should be used for arithmetic casts. This would provide a clear distinction between these two (or three) rather different worlds of casts. On other words, when you are performing an arithmetic cast to int specifically, (int) x is actually the way to go, not static_cast<int>(x). — AndreyT 5 hours ago
First time I read something like that...
 
guys could i ask u a question in c?
 
@rubenvb And from a high rep user.
 
user1804599
7:51 AM
1) you are not "i"
2) we are not "u"
3) no
8
 
is it possible to sort a set of names in alphabetical order without using strcmp and strcpy
 
Does anyone have the question that explains what a C style cast is in terms of C++ casts?
 
@rightføld sorry
 
@Vicky Yes, you use std::string and operator<.
 
He has a point in that C casts on numeric types are kinda well defined.
 
7:52 AM
Parlour<C++>
 
user1804599
Use std::set. It's already sorted.
 
@rubenvb Well, seeing that ABI is not required to be compatible even when changing a compiler flag with the same compiler, I make it a habit to not actually rely on that too much. I guess you are right, but in principle, it need not be the case
 
@rightføld @rubenvb thanks a lot will check it out
 
@Sofffia Oh. That's clear. "Yes". There, I added information.
 
7:53 AM
ikr
 
@Vicky Well, yeah, std::set and std::string, or std::sort on any other container.
 
@rubenvb all these are c++ based right
 
C++ based?
 
@Vicky Have you looked at the name of the room?
 
yes ... i have to do it bot in c and c++
both*
 
7:56 AM
I'm sorry
 
Then write it in C++ and make an interface to C.
 
@rubenvb
 
And I feel sorry for you.
:-p
 
oh ok ..... @rubenvb thanks a lot for your help
 
777
Q: When should static_cast, dynamic_cast, const_cast and reinterpret_cast be used?

e.JamesWhat are the proper uses of: static_cast dynamic_cast const_cast reinterpret_cast C-style cast (type)value Function-style cast type(value) and how does one decide which one to use in a specific case?

I don't know exactly what you were looking for of course
 
cpx
7:59 AM
This answer makes it clear a bit for me.
About the sizeof(std::string)
 
7 mins ago, by rubenvb
Ah here we go: http://stackoverflow.com/a/22999708/256138
But thanks anyway :-p
 
@rightføld missing 4) ???? 5) Profit!
 
But hey, that's a lot better than the one I found.
Should I close mine as a dupe?
 
@rubenvb IDGI. That's not the canonical one, so what is in there that is more informative
 
cpx
Anyway, I've always used std::string::size().
 
8:01 AM
@rubenvb Ah
@rubenvb I dunno, which is "yours"? I didn't keep track of OPs and answerers
 
@sehe My linked answer/question.
It's not mine by ownership or anything.
But it seems like a valid duplicate to me
 
Ah we might. It's old as hell, so I tend to let it be
 
user1804599
Screw Digital Ocean.
 
@rubenvb It does. Lemme do it :0
 
user1804599
Rackspace ftw.
 
8:02 AM
@sehe ok, go right ahead :-p
a root terminal on Linux should timeout IMHO.
It's a big security hazard.
I keep mine open sometimes, that's not so smart :-/
 
@rubenvb this is a solved problem. It's what sudo is for
@rubenvb Change terminal background or prompt to a signal color. This makes it harder to forget
 
@sehe My root prompt is red, I did that, doesn't help :-p
 
@rubenvb by the way, for these things is my one-stop shop. Order by votes.
 
@sehe sudo makes the user password valid for root operations.
That's bad.
 
@thecoshman WTF is this?
 
8:05 AM
Although doing everything as all-powerful root is also bad.
There should be an easy way to select user's su permissions
 
@rubenvb It depends a lot on how it's configured, but yeah, by default.
As I've argued on more than one occasion, the versatility of sudo is widely underestimated
12
A: Set sudo password differently from login one

derobertIf you want to ask for the root password, as opposed to the user's password, there are options that you can put in /etc/sudoers. rootpw in particular will make it ask for the root password. There is runaspw and targetpw as well; see the sudoers(5) manpage for details. Other than that, sudo does ...

 
@sehe Yeah I bet, I never got it set up here on my Arch install.
Maybe I should look into how I can make it better than the lame Ubuntu way.
 
@sehe I was just reading this as well
That makes choosing the commands quite difficult.
Also I'd like to be able to do pacman -Syu or pacman -S somepackage but not pacman -R somethingimportant.
But as it stands, linux is a bad customer to fine grained usability security.
 
@VáclavZeman scroll down you pleb, I link to the twitter account it's from.
 
8:09 AM
IMHO.
 
@rubenvb Actually, you can figure out what you need root privs for. For me, it turns out to be a limited set of routine tasks. As for less, it never needs to run as root. Add the user to the respective file's group.
 
@thecoshman Ah. Bad security advice tweets?
 
@rubenvb Yeah, that's ... enormously complex. That's not something I'd deem solveable. Except, thinking laterally, by using UML, Linux Containers, chroot jails or similar
 
@sehe yeah, but it's an example of how a seemingly unrelated program can be used to hijack a secure execution environment. I bet there's a lot more commands that can be misused to get a root shell.
 
@rubenvb I'd agree. OTOH the UNIX simplicity does go a long way for actual security too
 
8:11 AM
@sehe True, never argued linux wasn't secure. It's just hard to plug all the holes if you're not using the big concrete door.
 
@rubenvb All true. For real security look at (usermode) virtualization/isolation. For "adequate" tamper prevention or "siderails", sudo is plenty for my taste
@rubenvb That's not a property of UNIX. It's a property of software (and OS-es in particular). It's just that Linux (and other UNIXen) have not attempted to paper over this fact (too much) (yet).
Linux did so out of pragmatism, I think (no resources for that, no interest in/access to standardizing);
Other UNIXen, interestingly, also focus on app-virt and containers (point in case: Solaris). So I guess there's some more merit than mere time-efficiency
 
Yeah I fully understand that. Still, thinking about the fact that the same shell I run a system upgrade from can bork my entire system and reduce it to shreds is quite shocking.
 
Does Oracle still develop Solaris or is it just in maintenance / slow death mode?
 
lol Solaris.
Hey look, an OS that can run all our software!
But has a terrible amount of quirks that you meet when trying to do anything else.
 
Solaris is fine. You sound like you're thinking of other UNIXen (AIX? Tru64? HP/UX?)
@rubenvb Really. I think it's a fact of life. It's really no different for any other OS. I think it's far more worthwhile to have backups, and for critical systems configuration monitoring/sanity checks. (And that's outside the application-level availability measures, like clustering)
 
user1804599
8:22 AM
Is there a portable way to detect whether an header file can be found during preprocessing?
 
user1804599
Portable as in clang, GCC and MSVC.
 
@VáclavZeman I think of them as comical.
 
user1804599
IIRC clang has __has_include.
 
user1646075
@rubenvb See also $TMOUT.
 
8:23 AM
@rightføld nope
@rightføld ah you even meant in-code. Double nope then
 
user1804599
I want to disable a single overload if Boost.Filesystem does not exist.
 
@aclarke woot
 
@Xeo The only interesting thing for me is Unreal Engine.
 
@rightføld you will need to have different build configurations. This is the autotools niche
 
user1646075
@sehe God Bless man 1 bash
 
8:24 AM
@rightføld compile a test program like autotools does. CMake can do this as well.
 
user1804599
It's for a header-only library. :'(
 
@aclarke I bless man bash | less +/TMOUT
 
user1804599
Can still make a tool that generates a header, though.
 
@rightføld Document a preprocessor directive for the purpose. Boost Config might already have one
 
@rightføld well yeah, generate a config.h header and include that in every libary header.
 
user1804599
8:26 AM
Well only in headers that need it. :P
 
header only does not mean "needs no install"
 
user1804599
And no linking.
 
user1646075
eek:
 
user1646075
Blue mass (also known as blue pill or pilula hydrargyri) was the name of a mercury-based medicine formerly common from the 17th to the 19th centuries. The oldest formula is ascribed to one Barbarossa, in a letter to Francis I of France. == Description == Blue pill was also used as a specific treat syphilis from at least the late 17th/early 18th century. Blue pill was recommended as a remedy for such widely varied complaints as tuberculosis, constipation, toothache, parasitic infestations, and the pains of childbirth. A combination of the blue pill, and a mixture called the common black draught...
 
> For the Roman Catholic Blue Mass for law enforcement professionals, see Red Mass.
 
user1646075
8:27 AM
kid #1 just asked me if a broken fluorescent bulb is safe, and that lead to a Wikitrek
 
lolwut
@aclarke depends on type, but in general it's not riskfree, I wager (there's some gases that might cause problems when in direct contact with eyes, respiratory system?)
 
user1646075
Red Mass for communists?
 
user1646075
@sehe they have mercury vapor which emits UV when it gets zapped in the tube...
 
user1646075
cleaners have to take care but casual cleanup is ok. Playing light saber with them is also not recommended.
 
user1646075
the 2nd stop on the trek (mercury => mercury poisoning => blue mass) mentions all sorts of horrible symptoms
 
8:29 AM
3
A: Millimeters in boost::units

Tony The LionIf you have a C++11 capable compiler you could use User Defined Literals for defining your units. double operator"" _millimeter ( double value ) { return value; } You can use that like so: double foo = 1000_millimeter;

@TonyTheLion what was ^ that about? o.O
 
user1804599
@sehe dat UDL
 
@rightføld dat lack of Units
 
user1646075
exciting to see units getting attention in programming languages now. I hear F# addresses them somewhat...
^^-- clearly I'm too easily excited...
 
@EvgenyPanasyuk I like the second approach for spirit-ness. I like the first one for sheer ambition. I'd probably not accept that in code review (because complexity that's harder to reason about). But it's still cool
 
user1804599
@sehe -1
 
user1804599
8:33 AM
@TonyTheLion go for peer pressure badge!
 
@aclarke Not at all. Units are a big thing in certain domains
 
user1804599
F#'s unit support is nice.
 
user1646075
@sehe it was an issue for me in my first few years; coding for engineers. I thought at the time it would be nice if the compiler could validate that.
 
user1804599
I wish I had units last year. I often confused boxes (which contain articles) and articles, and kilograms and grams.
 
user1804599
8:34 AM
Though I rather have units not encoded in the data type, only quantities.
 
user1646075
@rightføld How does it go for things like - ummm - say units of screen coords vs. window coords; or ... ummmmmmm radians vs. degrees, that sort of thing? I think it could be a very general thing.
 
user1804599
(So 10m and 10mm would have the same type but different values.)
 
user1804599
@aclarke You can create custom units.
 
user1646075
@rightføld ooooooo!
 
user1646075
with conversions and offsets?
 
user1804599
8:36 AM
No offsets I think, but conversions are possible I think.
 
user1646075
cool. F to C stands out as needing an offset
 
user1646075
or just getting a compiler complaint would be a great leap forward.
 
user1804599
Encoding units in the type is extremely silly.
 
user1804599
You want a temperature type, not a Fahrenheit type.
 
user1804599
Fahrenheit should be a constructor.
 
user1646075
8:38 AM
depends... 'safe' and 'unsafe' nature to strings (eg for HTML purposes) is another thing that springs to mind, but not quite a dimension there really. More of an attribute. All this is just speculation.
 
It isn't. Scale makes a difference.
 
user1646075
@rightføld yeah, that's a good point
 
If you store everything as millimeters, parsecs are going to be trouble.
 
user1646075
although didn't a Mars mission have a last-minute failure due to imperial vs. metric failure in the engineering?
 
user1804599
Storage is an implementation detail.
 
user1646075
8:39 AM
@R.MartinhoFernandes how many bits would that need
 
@R.MartinhoFernandes bah, just use 1024 bit computers, problem solved :P
 
@rightfold Yes, one which you want to make observable, apparently.
 
user1646075
angstroms per newton-furlong
 
@aclarke distance per force distance?
is that like a unit of stretchability?
 
user1646075
farthings per newton-furlong? better?
 
8:41 AM
or elasticity I should say
@aclarke sure... cost per force distance.
not by much though :S
 
user1646075
you can count on computers!
 
user1804599
@R.MartinhoFernandes I do not.
 
@aclarke they exist. Boost Units calls them absolute vs. relative units (F = relative, K = absolute)
 
user1646075
ahhh
 
@rightføld Actually, you can have both - the temperature dimension, and the C/F/K units for that dimension
 
user1646075
8:44 AM
@sehe is temp really a dimension? What do physicists class it as? WIKI!
 
@sehe meh that was probably just one of those days I was trying to garner rep...
 
user1646075
mehh - some crap about energy and entropy.
 
@sehe K is relative, relative to zero.
 
user1646075
If someone says that "it's all relative" I say "absolutely!"
2
 
@rightføld Hiding the scale doesn't make it unobservable.
Or do you plan to use MPIR all over?
 

« first day (1454 days earlier)      last day (3497 days later) »