« first day (1325 days earlier)      last day (1533 days later) » 

5:41 AM
Does signed char type is introduced because to represent one byte signed integer?
Is it only the reason behind it?
 
 
4 hours later…
9:21 AM
hi
 
9:52 AM
Hi, I have a short question probably not suited for an SO post: In a quite old, large code base I found this:
```
Type& foo() {
return *_foo; //_foo is defined as: Type* _foo;
}

// later in the code
if (&foo()) {
foo().bar(); // Type has a method bar()
}
```

Is this how it is supposed to work? It looks strange to me, but the code does not crash and behaves as expected (compiling with MSVC).
 
 
3 hours later…
1:15 PM
public:
    LRUCache(int);
    void refer(int);
    void display();
};
is the constructor (of the C++ implementation)
 
1:55 PM
@PhilLab looks like potential undefined behaviour to me..
70
A: Is null reference possible?

Steve JessopReferences are not pointers. 8.3.2/1: A reference shall be initialized to refer to a valid object or function. [Note: in particular, a null reference cannot exist in a well-defined program, because the only way to create such a reference would be to bind it to the “object” obtain...

@Permian do you have a question?
 
usually a constructur is a function with the same name as the class
 
2:10 PM
@Permian Yes? It's the case here.
 
do there isnt a function
just function declaration
 
Oh? I see it first thing after the declaration of the class:
// Declare the size
LRUCache::LRUCache(int n)
{
    csize = n;
}
 
yeah thats a constructor
but whats the point of the thing i first posted
 
It's the declaration of the three methods of the class LRUCache
 
why do you need it?
youve defined them elsehwer ein the class
 
2:13 PM
The declaration of the class is the "contract", it tells the world what the class is. You can then either define the functions directly in the class, after the declaration of the class (like it's done here), or in a cpp file.
 
i dont think ive seen it before
 
What have you seen before?
If you want to write your class in your main.cpp, you need to write everything in a single file, either like it's done here, or by defining the methods right in the class declaration.
 
all of c++ i thought
haha
 
Commonly, the class will be delcared in the header files (.h), while the functions will be defined in the cpp file.
 
yes exactly
in newer versions of cpp are they going ot get rid of .h files?
 
2:17 PM
I haven't read much on that, I think you're thinking about "modules"?
 
no, like you write a .cpp file with your program in and a .h file with the declarations
 
@Permian That I highly doubt
 
but essentially the .h file could be superflous
other languages dont do it
 
Yes, it looks like c++ modules, or at least, the little things I read about it.
 
2:34 PM
@Permian You could also write everything in your .h files, but that would make the compilation of your code slow.
 
i still dont understand this lru cache
whats the relationship between the keys, the values and the node.value's
 
Question: Does anybody know how many bits can be stored in one single address?
I just made a string containing numbers and chars, found out that example address 6422208 were containing 2 numbers/letters or combination of these. Why?
 
@MZ97 Are those letters/numbers only 0-9 and A, B, C, D, E and F?
 
2:52 PM
@Vaillancourt thats correct!
 
i stuck my problem on cs se cs.stackexchange.com/questions/121180/…
 
@MZ97 It's not "two" letters/numbers it's an hexadecimal representation of a single character. ascii characters go from ~0 to ~127, you can take out your OS's calculator, in "programmer" mode and check the conversions between decimal and hexadecimal values.
@Permian Can't help you with that at the moment, sorry.
 
no worries
 
@MZ97 non-sequitur, an address just points at memory. The pointer doesn't determine an object type
 
Aha I get it now! So these numbers were saved as hexadecimal (int) using "0x" in front.
 
3:03 PM
@MZ97 no? They were just the binary value of the bytes?
 
@MZ97 The 0x is just a way to tell that they're displayed as hexadecimal. Everything is stored as binary, the programs only displays them as hex, because, well, 2 characters are shorter to read, memorize and interpret than 8.
 
hmm, I dont understand. I have it like this: unsigned int number= 0x01234567
 
Yeah?
You tell your compiler that the number is an hexadecimal one.
 
if i have an array, A, there's nothing wrong with negative array indices, as long as i ensure that A points to the middle of the array---right?
 
You could have written it: unsigned int number = 19088743; which would have given the same results.
 
3:06 PM
@AmagicalFishy other than undefined behavior?
 
@Vaillancourt Correct, and as I see, one address can store up to 8 bits. Thats why this is storing 2 numbers, each of them having 4 bits length.
 
why is that undefined behavior, given that accessing array elements by index is just pointer-arithmetic?
(and, if A points to the middle of the array, then A[-1] is the element before the middle)
 
@AmagicalFishy Because of how objects and lifetime work IIRC, but @nwp would have to weigh in
basically if you're not pointing to the head of the array then you're pointing at a single object not an array
remember that c++ is an abstract machine
Most pointer arithmetic that people think of that way is actually UB in many cases
 
ah, that makes sense. so if i set A to point to the middle of the array, then kind of "by definition" i just have this free floating pointer that i'm doing arithmetic on
 
correct AFAIK
 
3:09 PM
and it just so happens that i'll limit my arithmetic to stuff inside of, what might otherwise be considered an array
 
you can still compare it to pointers legally within the same array
but it gets really murky when doing actual math and access
 
@MZ97 One address stores 8 bits. Your compiler, debugger, etc shows them to you as 2 hexadecimal characters, each hexadecimal character being associated to a string of 4 bits. Bits are stored in addresses, everything else is a convenience for representation to us, humans.
 
@Vaillancourt technically it points to a location in memory which is usually an eight bit byte
 
that makes sense. when it comes to storing coordinates in an array, do people generally just avoid negative coordinates, or have a more elaborate structure where the indices of the array don't correlate w/ the coordinate's position?
 
but... it gets complicated really really fast
@AmagicalFishy Coordinates? in what sense?
as in pointing to stable locations in an array?
 
3:11 PM
like coordinates on a cartesian plane
 
@Mgetz Yes. My point is only that "hexadecimal numbers" are not stored, they're just a convenience.
 
@Vaillancourt correct, it's two characters to a byte, in other systems hex may make less sense
 
let's say (HYPOTHETICALLY, OF COURSE :D) i'm generating a height-map, so each (x, z) coordinate is associated w/ a height
 
Octal usually works better there
 
my initial thought was to use a 2d array where the indices would correspond to the (x, z) coordinates, and the value would correspond to the height
but that'd limit me to only positive coordinates (which isn't like... bad or anything). just wondering what people typically do when they need to (for whatever reason) represent negative coordinates
probably just translate?
 
3:13 PM
@AmagicalFishy or you could cheat and create a class called texture that wraps a vector and does the math internally?
 
i could do that too, yeah
 
that way you can do things like wrap if you want to...
 
i'm definitely over-optimizing here, but doing so out of curiosity ;D
 
so you can't actually cause UB
 
that makes sense, yeah. i think i'll go with that
ty :)
 
3:16 PM
I do actually wish C++ had texture primitives and such.... but it doesn't really make sense for the language
it's much easier to access something with GPU like texture systems
 
 
4 hours later…
6:51 PM
Hey! I have read a binary file and used fread to insert one byte of this file into 'unsigned char' variable. I want to access all the bits (eg. 0 to 7). Anyone who could help?
 
@MZ97 Like this?
47
A: Access individual bits in a char c++

MattIf you want access bit N: Get: (INPUT >> N) & 1; Set: INPUT |= 1 << N; Unset: INPUT &= ~(1 << N); Toggle: INPUT ^= 1 << N;

 
nwp
@AmagicalFishy You're not allowed to point outside the array except 1 past the end and you are only allowed to do pointer arithmetic when pointing to elements of the same array. If you have std::array<int, 42> a{}; int *p = a.data() + 10; p[-5] = 42; then that is legal. What Mgetz probably remembers is situations like int a[10][10]; int *end = &a[0][0] + 100;. I think that's not legal because that doesn't count as "same array" anymore and is technically UB.
I failed finding the relevant passage in the standard on a quick search to know for sure. Might got it another try later.
 
 
3 hours later…
9:44 PM
0
Q: C++ RtlDecompression or RtlDepression?

CastielI used RtlCompressBuffer to compress a png image. My problem is when I try to unpack it using RtlDecompressBuffer I get the following output (the image is incomplete). What is wrong on this side? Function: DWORD FinalUncompressedBufferSize; PBYTE OutputBuffer = PBYTE(LocalAlloc(LPTR, 4096)); ...

Can anyone take a look?
 
10:07 PM
Hi,
Let's imagine that we have a certain object `int x` with a value, for example, 12345 - this value of `x` doesn't fit into the range of representable values for `char`, then the result of dereferencing the expression `*((char*)&x)` - UB?
 

« first day (1325 days earlier)      last day (1533 days later) »