« first day (1689 days earlier)      last day (1147 days later) » 

12:36 AM
Can I ask plain C questions here?
 
1:00 AM
@BlockofDiamond Yeah--though depending on the question, you may or may not get an answer (oh, and try to be patient if somebody doesn't notice, and gives you a C++ answer).
 
 
2 hours later…
2:44 AM
@JerryCoffin Ok
 
psy
3:40 AM
Hello!
// a.cpp
void process() {
mystruct *data = mystruct_alloc(...);
callback(data); // could be a coroutine, thread etc... Therefore, the callback method needs to free data
}

// b.cpp
void callback(mystruct *data) {
// process data
mystruct_free(data);
}
mystruct_alloc()/free() are defined in a library. The above code works.
I want to use unique_ptr instead of pointers.
using mystruct_t = std::unique_ptr<mystruct, decltype(&mystruct_free)>;

// a.cpp
void process() {
mystruct_t data(mystruct_alloc(...), mystruct_free);
callback(std::move(data));
}
The above code fails during linking: undefined reference to mystruct_alloc and mystruct_free
It fails inside some library function.
 
4:20 AM
@psy I think you've left out too much detail to be able to diagnose the problem.
 
 
3 hours later…
6:58 AM
Does anyone remember where the question about why sometimes arguments "can" be swapped in variadic function (like printf("%i %f", 2.0, 1) prints 1 2) is? Or is it deleted?
 
7:17 AM
Don't remember the question.
However, what's probably happening is not that the arguments are swapped.
The 2.0 has a floating point binary representation but it's reinterpreted as integer, which happens to be 1.
And vice versa.
 
7:40 AM
Yes of course I know what... wait!?
I didn't try running that code, but the reason is the x64 calling convention.
It's undefined behavior anyway.
(it pass integer and floating point variadic arguments in different registers)
 
 
4 hours later…
11:50 AM
8 messages moved from Lounge<C++>
1 message moved from Lounge<C++>
 
 
5 hours later…
5:07 PM
Hey all,

I think I've figured out what I'm doing wrong with Unicode printing to console. I found a program that successfully used `_setmode(_fileno(stdout), _O_U16TEXT`, but I'm getting an error C6031 (Return value ignored: "_setmode") and I'm not sure how to resolve it. The Microsoft documentation on the error isn't making much sense. Does anyone know what to do?
 
auto result = _setmode(_fileno(stdout), _O_U16TEXT);

Maybe you have some very high warning levels enabled
 
That's maybe possible? I am running in debug mode and I guess I'm not sure how to disable to warning. I just know that it keeps giving me a failed assertion that seems entirely incomprehensible.

I tried including that line and printing `result` and it doesn't seem to have fixed anything; is there something else that I should be doing with `result`?
 
mabe it was fileno, seems weird though

auto f = _fileno(stdout);
auto result = _setmode(f, _O_U16TEXT);
wait? Failed assertion? Why are you posting a compiler message then?
 
Tried and failed; I'm getting the assertion when running the debugger and getting the compiler error beforehand.
 
well the compiler warning is not your problem
 
5:24 PM
Ignoring the assertion gives the message "Unhandled exception at memory address 0x7AEBF2F6...An invalid parameter was passed to a function that considers invalid parameters fatal"

VS is placing the exception on _setmode(f, _O_U16TEXT) from the look of it
 
seems like maybe _fileno(stdout) is giving you back -1 for some reason?
> If stdout or stderr is not associated with an output stream (for example, in a Windows application without a console window), the file descriptor returned is -2. In previous versions, the file descriptor returned was -1. This change allows applications to distinguish this condition from an error.
looks like you don't have a console window when you execute that function, you working on a GUI app?
 
Nope; full disclosure, I'm just learning the functionality of the language right now and I'm a beginner where programming is concerned. I figured that C++ was a good place to start, but I keep finding things that I want to do that end up being way more challenging than they should probably be.

Once I can actually get the thing to work, I'm probably going to try to make a little roguelike game project with some symbols outside of the basic ASCII set. It'd be nice to be able to use the box-drawing characters (╔╗╚╝╠...) instead of hashes for walls, for example.
Everything I've read suggests that the _setmode() function is the ticket, but it's spotty in execution from what I can tell. I've also tried the chcp 65001 trick, but with similar results.
 
So what's the value of the result for `_fileno(stdout)`?

Also, did you try just running the executable from a normal terminal, not from inside visual studio?
 
The console window is opening, but the assertion pops up immediately and no output comes up other than an exit code 3. I'm not getting values for either _fileno(stdout)or _setmode()
 
5:40 PM
what do you mean by "not getting values for"?

Set a breakpoint or step through and see what fileno returns
 
What I'm finding for exit code 3 suggests that it's a memory issue, but it's not entirely specific. My machine has plenty of memory though, so I don't see how it would be running out of resources.

I'll do a check on that.
 
I wouldn't put too much stock in the application return value of a crashed process
 
```
```
auto f = _fileno(stdout);
auto result = _setmode(f, _O_U16TEXT);
std::cout << f << result; //error here
```
 
well the error happens in setmode, so you need to print before that
 
f has a value of 1 and result is 16384
Just checked again to be sure, f is definitely 1
 
5:43 PM
huh, maybe I misunderstood, I though the crash was in setmode
the cursor in the debugger always points to "this will be executed next" though, not "I am executing this"
 
Right right. On the line with setmode though, the yellow arrow goes grey and becomes more of a curved arrow, then a red 'x' pops up to the right of that line.
So I imagine that that's where things are going funky, but it's beyond my depth in all honesty.
There is this post, but I'm not sure that the answer addressed the issue: stackoverflow.com/questions/45232484/…
 
It honestly sounds a bit like there's something weird with the surrounding build-setup or program

If you just don't use setmode, does it stll crash?
 
```
_setmode(_fileno(stdout), _O_U16TEXT);
wprintf(L"\x043a\x043e\x0448\x043a\x0430 \x65e5\x672c\x56fd\n");
```
I guess with this as a different example, I get the following: КОШКа □□□, followed again by a crash on that assertion that claims the exception at some memory address.
If I don't use setmode, say if I'm using chcp 65001 or just trying to print without formatting, it doesn't crash, but the output is either boxes or absent from the console entirely.
I watched some CPPCon stuff the other day and it seems like they're having a real hell of a time trying to figure out how to implement UTF-8 and so forth, but at the same time I figure that there are plenty of machines out in the world that use it without a hitch.
 
6:01 PM
did you mean \u043a etc ? I though x was not for wide-chars, I'll look it up
 
Apparently both \u and \x are supposed to work, although I'm not sure what the difference is. It runs the same if I switch them out.
 
I don't really understand how the console output is triggering an exception. That seems so weird to me
Sounds unrelated actually
is it really just a wprintf(L"\x043a\x043e\x0448\x043a\x0430 \x65e5\x672c\x56fd\n"); followed by a return in the main function?
 
Yep. Just the two lines. I've got #include <io.h> and #include <fcntl.h> in the mix because I was told to use them.
 

« first day (1689 days earlier)      last day (1147 days later) »