« first day (1192 days earlier)      last day (1652 days later) » 

7:43 AM
I know right. WinAPI is safe, as long as people dont do intently bad things ,haha
 
 
2 hours later…
9:40 AM
Hey guys
 
Hey guy
 
10:00 AM
HiHi, waving hands
What will happen if I write a number( >INT_MAX ) in runtime to an int?
Is it UB? will the programm abort immediately? or it depends on different OS?
 
signed integer is undefinded behavior, unsigned integer is defined
 
Hi @PeterT can I ask you something?
 
you just did, so why not go for another?
 
Ah, thanks. I saw people talking about C++ server side programming, for exmaple gaming server side programming. But for exmaple all the linux API are implemented in C.
Then in which way C++ makes a difference I wonder?
 
10:15 AM
All of Win32 is also a C API. Most operating system APIs are at the lowest level C APIs because C actually has a stable defined ABI.
If you want to use C++ features, use C++, if you think C is enough, use C
 
Hmmm.
So I can just include POSIX API directly in my C++ project and then mix C with C++?
I am new to socket programming. That's a stupid question I know ;(
 
Oh, yeah sure, you can pretty easily use C API with C++
just doing
extern "C"{
#include "some_c_header.h"
}
is about all you need to do
there's some newer C features that could potentially cause issues, but they're rarely used in the header files. Especially for APIs that are also used by other languages and their FFI
 
Then the only benefit comes from C++ language itself? For example, OOP, vector sort of thing?
Is there C++ libraries that wraps those low level linux C api, does the dirty work and I can just directly include some header files and call the function in a C++ manner/OOP way? Or in fact that's unecessary?
 
I don't know any such library. There's a bunch of higher-level network libraries that use sockets under the hood.
If it's just sockets then doing a simple RAII wrapper is just not that big of a plus imho
 
OK thank you. I got the idea. ;)
 
 
2 hours later…
12:23 PM
@ratchetfreak you should probably add either @PeterT or myself as ROs as we're more active here as late
 
1:14 PM
I wonder why the return type LSTATUS from WIN API is defined like this:
typedef _Return_type_success_(return==ERROR_SUCCESS) LONG LSTATUS;
 
probably SAL annotations
 
I mean, whatever the error might be, the error code will not be returned. And people cannot see it.
 
? it's for static analysis purposes, so the analyzer knows what the success code is
 
@PeterT no probably about it
That said it looks like SAL is going to largely get replaced with attributes
and contracts
 
1:30 PM
It was a good tool for Microsofts internal use and they badly needed it, if you look at Windows ME.
 
@PeterT windows ME wasn't actually problematic per se, the switch in driver models was. This is why ME was a failure as an upgrade. ME really forced the WDM, moving away from the legacy DOS drivers that 98 supported as legacy (but people used because lazy).
this happened in XP too FWIW
 
@PeterT But don't people need to know what kind of Error the API throws? How do they do it? with logging? But I do not see people in my company do it..
 
@DexterLiu it's in the documentation? It's a C api, documentation is required
 
you are right , I see it :see_no_evil:
 
it's a typedef, it's still a proper integer variable but I don't know the details of how that black magic gets interpreted
 
1:35 PM
@ratchetfreak it's basically a work around for the fact that it is just a typedef and so it lets the analyzer check to see if people are checking the return correctly
 
 
1 hour later…
2:45 PM
Damn I didn't realize that using C functions in C++ would be so easy. Just wrap anything with extern "C" { include <sys/socket.h>} and then it's good to go . :(
No extra work at all.
 
@Rick Really shouldn't even need to do that in most cases as they are system headers?
which should do that internally
 
@Mgetz Hmm that's true. But I don't know if they do that internally.
 
#ifdef __cplusplus is how
 
@Rick try it first and then worry about it
don't assume system headers aren't compatible
You can actually break things doing that as some have C++ only exports
 
Oh, I see you mean I can include it directly at first and compile, run.
 
2:52 PM
usually
System headers are almost always c++ compatible with a few minor exceptions for legacy reasons I'd have to look up
 
@Mgetz ok that's really good to know that.
 
just don't include any X11 headers, the have some of the most annoying macro names in them. They are the second most annoying header after Windows.h that I've encountered
 
@PeterT The windows team has been desperately trying to fix their headers but there are legacy issues
either way... WIN32_LEAN_AND_MEAN is basically a mandatory define
I also do NOMINMAX
 
@PeterT I clicked "go to declaration" and do a simple search with ( extern "C") keyword. I didn't find any match so then I decided to add my own extern.
 
@Rick it's in a macro
not explicit
usually _BEGIN_DECLS
 
2:57 PM
@Mgetz what does it mean? If anything, shouldn't they exist in the header file?
 
@Rick it means explicit extern "C" may not be visible
 
Ah I got the idea. The library may define a MARCO standing for that.
And I don't know which MARCO may stand for it.
ok I see.
@PeterT What are the X11 headers? I am basically learning on Ubuntu right now. Maybe for now I won't encouter with those headers.
 
Basically old graphical interface headers, you might encounter them if you do anything with GUIs
 
@Mgetz Another (and last) question. If I include a C library function and compile without error. Does it ensure that the library I included is C++ compatiable and then I can safely use it?
@PeterT Ok got it thank you Peter.
 
nah, there's no checking.
 
3:09 PM
Ok. So as Mgnetz said, for system headers, in most cases just use it directly. Other C libraries, check the documentation on your own.
Oh cool. I found _BEGIN_DECLS.
 
 
2 hours later…
nwp
5:00 PM
@Rick That's not useful and you should never write that. Either it has no effect or it's an ODR violation which most likely causes it to fail to link.
 
 
2 hours later…
6:50 PM
Are Zw and Nt APIs exactly the same?
 
there is a very very significant difference
also never use those from userland
 
For system calls from user mode, the Nt and Zw versions of a routine behave identically that is good news..
 
still never ever call them from user mode
 
I am calling...
 
7:05 PM
what?
 
I am using Nt functions now xD
Why I should not use them?
 
don't call any of those directly
they aren't stable
that API is not for userspace use
 
But aren't they called inside Win API?
 
@DexterLiu whether they are or not is irrelevant. You shouldn't use those in userspace unless there is literally no other way to do what you need.
WIN32 is stable and documented
calling an undocumented API (and it is considered undocumented as far as user space goes) is not supported and may break at any time.
 
Ok. It is not used all the time, just for special cases. Because WIN API cannot handle \0 byte inside string, so only for this case, I use Nt API
Thanks for the great INFO!
 
7:14 PM
@DexterLiu most new WIN32 methods can
depends on what it's being used for
 
Oh, sorry, forget to mention, it is about Registry
There is a malware writing '\0' inside strings to create Registry key
 
then sanitize it?
 
but you cannot find it in the Registry
like this RegEnumKey, it reads only until the \0
but the key is "\0abc" maybe
 

« first day (1192 days earlier)      last day (1652 days later) »