« first day (1358 days earlier)      last day (1477 days later) » 

12:07 AM
@northerner Thanks!
 
 
7 hours later…
6:55 AM
When I try to compile code on Ubuntu it gives undefined reference to pthread_create'` even though std::thread is used and not pthread
but adding the option -lpthread fixes it.
 
 
2 hours later…
8:43 AM
hey guys
does anyone know of the differenc between the binary search implementations that are while(l < r) vs the implementatiosn which are while (l <= r)???
 
partitioning l==r just doesn't do anything
so you might have a couple useless swaps in there with l<=r but it's not going to matter much
 
9:28 AM
why do we need overloading operators
and why dont we just use classic functions
 
9:42 AM
because a.add(b.mul(c.div(3))) is a lot harder to read than a+b*(c/3)
 
yes but i wanted to get smth related to more complicated reasons like maybe it can help you make a more general code to be inherited or idk
 
no, not really, they're just syntactical sugar mostly
you can see that in languages like Scala where every function is an operator, but that can lead to some rather badly readable code
 
user7659542
I am reading the SDM of my x86 CPU, which states:
 
user7659542
The Intel486 processor (and newer processors since) guarantees that the following basic memory operations will
always be carried out atomically:
• Reading or writing a word aligned on a 16-bit boundary
 
I have a program which occasionally gives the wrong result. Even with the same input 99% of the time it's correct but for some reason it's occasionally wrong. Does this mean there's undefined behavior somewhere?
 
9:51 AM
@northerner no, could be threading order stuff
which is not technically undefined, just unspecified I think
 
user7659542
But, 0x10 divided by 16 is not possible, ie it still has a modulus. So 0x10 is not a 16 bit aligned address. Am I wrong
?
 
user7659542
According to this post on SO, this means that 0x10 is 16 bit aligned
 
0x10 is a byte address, not a bit-address
 
user7659542
aaah... OK...
 
@traducerad 0x10 == 16
 
9:54 AM
also 0x10 is 16
 
user7659542
@PeterT true!
 
user7659542
Thanks!
 
also you were quoting some very different things, the 16-bit alignment of x86 is only spuriosly related to the 16-byte alignment of some SIMD instructions
 
so for 8-bit bytes you only need even addresses to be aligned to 16-bit boundaries
 
Out of curiosity how do variable length instructions works on CISC? I guess the first part of the instructor allows the processor to tell how long the entire instruction is?
 
9:57 AM
@ratchetfreak yes for normal x86 instructions, there may be additional requirements for SIMD stuff
 
yeah I would expect that simd reads and writes aren't atomic unless otherwise specified, especially because they aren't word-sized
 
10:37 AM
Valgrind is detecting race conditions and I may know why. What could go wrong if two threads modify the same element in a std::vector<vector> to the same value? For example t1 and t2 at the same time change myVec.at(1) = false
If both threads are setting it to the same value shouldn't it be ok?
 
11:04 AM
where can I find some book or exercices for cpa exam ? I cant find anything
 
11:38 AM
if i have an enum A {a,b,c,d} and i declare A var what data type has var?
 
@CătălinaSîrbu A?
The underlying type seems to be int or "bigger", as per this answer:
49
A: What is the underlying type of a c++ enum?

greyfadeThe type of a C++ enum is the enum itself. Its range is rather arbitrary, but in practical terms, its underlying type is an int. It is implicitly cast to int wherever it's used, though. C++11 changes This has changed since C++11, which introduced typed enums. An untyped enum now is defined as ...

 
i though is „enum A„
 
Can you have an enum A and a struct A declared in the same scope?
 
11:57 AM
nupe
 
Ok, perhaps the enum is irrelevant, fundamentally? ¯\_(ツ)_/¯
 
but let me understand there are 2 categories enum and enum class
then enum splits in typed enum and untyped enum ?
 
and in c++11 how can i declare an untyped enum
can you give me a link to typed enum as i only find enum class|struct
 
Well, they are always typed.
enum color
{
    red,
    yellow,
    green = 20,
    blue
};
This will declare the constancts red, yellow, green and blue in the parent scope of the enum.
(example from here).
 
12:06 PM
but what about the typed stuff
i dont see what is typed
they are not based on any type
 
This type is "unscoped".
enum smallenum: int16_t
{
    a,
    b,
    c
};
This will "force" the type of a, b, c to be int16_t.
 
oh now i better understand. Could you please provide a link to cpp doc?
 
thanks a lot
 
If you use "enum class", you'll force the scope of the enum, so the values will not be accessible through the "parent" code, but will be accessible only with the enum scope you specify.
:)
 
12:15 PM
what is attr used for?
 
12:29 PM
In what context?
 
I think she means in the standard parsing reference, it's attributes like [[unlikely]] [[fallthrough]] [[noreturn]]
 
1:09 PM
Is there still a race condition if both threads are writing the same value to the same element in a std::vector<bool>? I kind of doubt it because the values are the same.
 
1:33 PM
@northerner yes, for vector<bool> specifically yes
vector<bool> is an abominable hack that should not be used, it's some weird bitset like specialization instead of a bool[]
 
@PeterT can the problem be solved by implementing a thread safe vector with a mutex?
 
yes, you could lock a mutex everytime you write to the vector, or you just use std::vector<char>
the problem is that std::vector<bool> is not just one byte per entry, it does bit-hackery
 
Actually I still don't see what difference <bool> makes in this specific situation? As long as the same value is being addressed isn't that all that matters? How would <char> be different? @PeterT
 
if you write to std::vector<bool> a; a[0] and a[1] they both write to the same byte
I don't have the full program in front of me, but it's a bad idea to write anything to it with threads in general if you don't lock around it
 
that's a good point
 
1:48 PM
guys i have a little problem over here after defining a new input file object i get an error
error: aggregate 'std::ifstream file' has incomplete type and cannot be defined|
i wrote std::ifstream file;
 
@MyDoom did you forget #include <fstream>
 
and you are right
hhhhhhhhhhh
 
I am finding it difficult to really understand why the compiler synthesizes a copy-assignment operator declaration as a deleted function if a data member is const or a reference. Please can anyone demonstrate this with a simple example for me to understand it better?
 
2:03 PM
const int c = 5; c=6;
that simple enough?
 
2:14 PM
@PeterT, the second statement will fail right?
 
right, so any class that contains such a data memeber would need to fail too if it would do the default thing
 
That's understandable, because by the time the copy-assignment operator is called on the object, the object has already been created and the const member initialized? Okay.
 
yes
 
What of the reference?
 
well that's a little bit more complicated, you can't rebind a reference and it would be confusing in some cases if you would just call the copy assignment of the non-reference version.
 
2:20 PM
it's not clear
please can you illustrate?
 
I have been running b2 --prefix="..\" --toolset=msvc architecture=x86 address-model=64 --build-type=complete --link=static install, and boost was built, but it won't install, aka copying the libs to a place where I can include the folder properly. Any way to fix this? I am on Windows 10.
 
@octopus
it's confusing that
int b = 5;
int &a = b;
a++: //affects b
a = c;
a++; //suddenly doesn't affect c
@TuxStash.de maybe it's the backlash in \" depending on the terminal software that might be an issue
 
@PeterT Windows command shell, I don't think it is, but I'll try without it
@PeterT Unbelievable, it copies the files now. Thanks mate.
 
@PeterT does that means that the reason is just because the data member (of the left operand of =) that's a reference will remain bound to the object to which it did before the copy-assignment operation and not to the object the reference data member (of the right operand of =) is bound to, is why it's prevented?
 
@octopus I always just assumed that was the reason, I don't remember it being written down anywhere. The standard just says what the rules are, not why
 
2:34 PM
@PeterT thank you so much for helping me understand these
 
 
3 hours later…
5:33 PM
@Vaillancourt but an scoped enumerion still splits in two: fixed type and unfixed type also, right ?
and scoped enumarations has type int if not specified otherwise ? unscoped enumerations the same ?
@PeterT is this correct?
 
5:49 PM
looks right to me, I think the "unfixed" rules don't really exist for scoped enums. They just default to int when nothing is specified
 
i wanted to write this but i didn't knew how
"default int when nothing specified " i think best fit
so basically i could say that scoped enumerations are always fixed type enums, right ?
@PeterT
 
I guess. Whether you want to divide fixed/unfixed or whether you want to divide implicitly typed and explicitly typed is kind of arbitrary
 
ok thank you I wanted to have a good mind representation for this in order to not misunderstood
what is an Opaque enum declaration for an unscoped enumeration must specify the underlying type. used for ?
also, what exactly do they mean by unscoped, is it synonym with global ? (for this case?)
 
6:10 PM
enum A : int; // Opaque declaration
struct B{A val;};
enum A{C,D,E};
nah, I think your diagram defines well what an unscoped enum is
 
the fact that they dont belongs to anyone?
I don't see it, help :)
 
no basically the "forward declaration"
it's declared without the enum values
"defines the enumeration type but not its enumerators" as the page says that you linked
 
6:41 PM
@PeterT I wanted to say that I don't understant what unscoped enum is :) The opaque declaration is clear for me, thanks!
 
You have that in your chart
it's the normal "enum" without the "enum class" or "enum struct"
 
ok so there is not proper definition for unscoped?
 
oh, you why it is called that?
it's because it doesn't create a new scope, the enumerators "leak" into the scope the enum is declared in
 
and the enum classes?
ohhh
i think i got it
 
enum A : int {B,C,D};
int e = (int)B; //ok, same scope

enum class A : int {B,C,D};
int e = (int)B; //not ok, B is not in scope
int f = (int)A::B;// ok
 
6:47 PM
thank you!
Declares an unscoped enumeration type whose underlying type is not fixed (in this case, the underlying type is an implementation-defined integral type that can represent all enumerator values; this type is not larger than int unless the value of an enumerator cannot fit in an int or unsigned int. If the enumerator-list is empty, the underlying type is as if the enumeration had a single enumerator with value 0).
what does it mean ?
 
it means if you do
enum A {B,C,D};
Then the compiler can make A be char, short or int , because A,C,B are only 3 values and can be represented by any of those types
enum A {B=500}
can only be short or int, because char would be too small
 
so you cant be sure what underlying type the compiler choose?
 
yeah, the compiler gets to choose if you don't say otherwise, but you can check by just doing sizeof(A)
 
so let's say enum A{B,C,D} gets interpreded by compiler as char values. What happends if i have more than 255 elements in the list? they are promoted to next integer type which can holds it ?
 
any type the values fit in, the compiler can just make always int, that's also valid
But, yes what you said is also a valid implementation
 
6:55 PM
or what happends if i only have 3 but the second it is explicitly stated as equal to 256 `enum A{B, C=256, D}
 
then it's not char
 
ok thanks a log that clarifies a lot
 
7:38 PM
@PeterT you said enum A {B=500} can only be short or int, because char would be too small but what about int_16 or uint16 these types cant be valid data type representations for enumerators?
 
yeah, they're probably valid too
 
what does this mean? canonical forms of binary operators are implemented in terms of their compound assignments
 
Seems like
5 + 6 =>
a= 5; a+=6;
 
what is the canonical form of binary operators
from the example you provided?
 
I think it's like "the ones defined by the compiler"
not sure
 
7:52 PM
but I still dont understand what is meant by that phrase
 
Yeah, I don't really get it either. Might be something like "You can define the operators this way and they will keep the same logic that's used for them normally"
 
i didnt test it but if you declare operator+, atutomatically its implemented the same way operator+=?
 
I don't know
 
8:08 PM
thank you very much for your time and sory if I bother you
 
Don't worry about it, this is just a chat room, if I don't want to answer I just wont. I'm interested in learning the details of C++ as well. That's what I like about Stackoverflow because people may ask questions I've never really thought of.
 
Ye but maybe you consider them (my questions) silly :))
 
You really shouldn't worry about what random people on the internet think. Or you should .. I don't know, not my area of expertise
 
8:36 PM
If I had for example int x=3;
Is there a way of putting the while of x inside a string literal ?
 
like std::to_string(x) ?
 
I want to throw a string literal, but can't be bothered with creating a separate string object just for that cause
@PeterT will that work?
Never used that before
 
it will work for all types it's overloaded for, including int
 
Yup, works like a charm
Thanks
 
8:50 PM
which is the diff between unspecified and undefined ?
 
In C++ unspecified is usually "compilers are allowed to do this specific thing in a specific way they want, but they have to do it so that the rest keeps working as described"

undefined means "the compiler can completely ignore what would happen if the programmer did this, it is allowed to crash, to work as the programmer expected, it's allowed to call 911 and have your arrested"
 
=) ok then
Values of integer, floating-point, and enumeration types can be converted by static_cast or explicit cast, to any enumeration type. If the underlying type is not fixed and the source value is out of range, the result is unspecified (until C++17)undefined (since C++17). ___(The source value, as converted to the enumeration's underlying type if floating-point, is in range if it would fit in the smallest bit field large enough to hold all enumerators of the target enumeration.)___ Otherwise, the result is the same as the result of implicit conversion to the underlying type.
 
9:05 PM
it means you can do
enum A {B=0, C=1, D=2};
int val2 = 2;
A val = static_cast<A>(val2);

But if you use a value outside the range like
int val2 = 6;
A val = static_cast<A>(val2);

then it's undefined
 
is undefined? or it is the same as you would convert to the underlaying type
e.g convert int to int in the example you provided
 
oh, nvm I think this is about the compiler choosing enum A being something like char and the value being larger than the the one representable by char
 
How is this working

enum access_t { read = 1, write = 2, exec = 4 }; // enumerators: 1, 2, 4 range: 0..7
access_t rwe = static_cast<access_t>(7);
assert((rwe & read) && (rwe & write) && (rwe & exec));
if cout << rwe & read; doesn't compile?
nvm i forgot the paranthesis
but i dont understand what is meant by this example assert((rwe & read) && (rwe & write) && (rwe & exec));
this is some weird stuff. enum access_t { read = 1, write = 2, exec = 4 }; contains 0b0001, ob0010, 0b0100 and they say that now a 7 which is 0b0111 in binary can be converted to that enum without undefined behaviour. How does it comes?
 

« first day (1358 days earlier)      last day (1477 days later) »