|
Volte posted:Unsigned int should usually mean "raw bit pattern" not "integer value that logically can't be negative". Sometimes even values that can't be negative can be subtracted from and you end up with really stupid bugs when the difference would be negative. Subtracting two vector sizes to get the difference between them? Better make drat sure to check which one's bigger first. Absolutely correct. Better than I could phrase it
|
# ? Jan 4, 2023 19:39 |
|
|
# ? Jun 7, 2024 07:52 |
|
There was a big push to do a "stl2" alongside ranges which would fix a lot of the incidental minor problems, and switching to using signed sizes and reserving unsigned for things you don't do math on was part of that. That project didn't get committee buy-in, though.
|
# ? Jan 4, 2023 21:47 |
|
Plorkyeran posted:There was a big push to do a "stl2" alongside ranges which would fix a lot of the incidental minor problems, and switching to using signed sizes and reserving unsigned for things you don't do math on was part of that. That project didn't get committee buy-in, though. (Though yuck, ssize_t and size_t, instead of size_t and usize_t)
|
# ? Jan 5, 2023 02:15 |
|
roomforthetuna posted:Non-serious counterpoint to signed sizes are good - Microsoft loving things up by using 32-bit size_t for posix file operations unless you go out of your way to #define some poo poo would be *even worse* if the accidental maximum size was ~2GB instead of ~4GB. Hahaha what the gently caress
|
# ? Jan 5, 2023 02:19 |
|
giogadi posted:Hahaha what the gently caress
|
# ? Jan 5, 2023 02:29 |
|
Is it bad form in c to write one over the other. From what I understand they should be equivalent since an array in c is just a pointer in disguise.code:
|
# ? Jan 9, 2023 12:12 |
|
I prefer the second because it isn't lying.
|
# ? Jan 9, 2023 13:15 |
|
Except when it's actually an array as in "int arr[3]".
|
# ? Jan 9, 2023 13:56 |
|
Beef posted:Except when it's actually an array as in "int arr[3]". This doesn’t work well in my experience, can’t remember why though
|
# ? Jan 9, 2023 15:06 |
|
Just here to echo that the landmines around ever subtracting from a size_t are real and one of the handful of moments that actually made me swear out loud during my return to C++ over the last few months. It should have been signed. I guess that we're still living with the decisions made when pointers were much smaller, and will be forever.
|
# ? Jan 9, 2023 15:31 |
|
Beef posted:Except when it's actually an array as in "int arr[3]". nope, that's not a thing
|
# ? Jan 9, 2023 15:54 |
|
edit: I may have misunderstood beef's point; deleting
Dijkstracula fucked around with this message at 16:14 on Jan 9, 2023 |
# ? Jan 9, 2023 16:10 |
|
There is actually a way to declare function argument that takes an array of **at least** n arguments, but the enforcement is that it is UB to not do that and maybe your static analysis tool will warn if you didn't pass in the right array.
|
# ? Jan 9, 2023 16:15 |
|
Xarn posted:nope, that's not a thing Ah crap, you're right. Better post caffeinated. quote:any parameter of array type is adjusted to the corresponding pointer type, which may be qualified if there are qualifiers between the square brackets of the array declarator (since C99)
|
# ? Jan 9, 2023 20:44 |
|
Note that while int* and int[] are identical in argument lists, and a type like int[5] is silently ignored / transformed into int*, you can have a variable of type "pointer to an array of length N" code:
RPATDO_LAMD fucked around with this message at 21:37 on Jan 9, 2023 |
# ? Jan 9, 2023 21:24 |
|
There are situations where it's a nice note for how many bytes an output parameter will return, likecode posted:bool read_2_bytes(uint8_t bytes[2]);
|
# ? Jan 10, 2023 15:14 |
|
Does anyone use Qt creator? I want to limit the clang to specific C standard: https://clang.llvm.org/c_status.html It says I can use something like -std=c90 Qt says it's an invalid option and discards it if I try to use it: Any pro tips? Do I need to put it somewhere else?
|
# ? Jan 10, 2023 16:32 |
|
Ihmemies posted:Does anyone use Qt creator? I want to limit the clang to specific C standard: https://clang.llvm.org/c_status.html What C standard are you wanting to use? C90 is not a standard, as the clang docs you linked mention you probably want c89 if you're trying to intentionally write c that builds with ancient or tiny compilers, but I'm curious what those are? C11 is really widely supported at this point.
|
# ? Jan 10, 2023 16:39 |
|
Maybe because -std is not a warning option?
|
# ? Jan 10, 2023 16:41 |
|
Twerk from Home posted:What C standard are you wanting to use? C90 is not a standard, as the clang docs you linked mention you probably want c89 if you're trying to intentionally write c that builds with ancient or tiny compilers, but I'm curious what those are? C11 is really widely supported at this point. I am doing a C course, which has automated checks for exercises. It gives prompts like: code:
OddObserver posted:Maybe because -std is not a warning option? Maybe. I don't really understand this. So it's not possible to get warnings about something like for(int i = 0; i < 7; i++) { ... ?
|
# ? Jan 10, 2023 16:41 |
|
I'm dumb, ANSI C is apparently also called c90 as well as c89, my bad. Yes, you want your compiler in that mode, and then just turn up the warnings.
|
# ? Jan 10, 2023 16:45 |
|
StumblyWumbly posted:There are situations where it's a nice note for how many bytes an output parameter will return, like C code:
C code:
|
# ? Jan 10, 2023 18:43 |
|
Ihmemies posted:
Edit: -Wc99-extensions may be what you were trying for, but you probably do want the -std for compilation as well. (See https://clang.llvm.org/docs/DiagnosticsReference.html#id145) So I don't know what Qt Creator is thinking, but the option stuck out since it doesn't enable a warning for those things, it makes them an error, so I was guessing Qt creator may expect you to put into some other bunch of settings (e.g. language settings for compilation?) OddObserver fucked around with this message at 19:30 on Jan 10, 2023 |
# ? Jan 10, 2023 19:27 |
|
I had to add Kits > Compilers > a manual compiler with flag like -ansi or -std=c90. Then use that Kit in the Qt project. I'm supposed to print a list of repeating numbers from an array, which gets its values as cmd parameter like 0.2 -9.9 4.32 0.2 -9.9 1.23 15 0.2 -9.9... I'm not supposed to create my own arrays, instead I must iterate over that argv array repeatedly. code:
If I just could make an array which tracks if a number from given index is printed or not... or something something Ihmemies fucked around with this message at 16:59 on Jan 15, 2023 |
# ? Jan 15, 2023 16:53 |
|
Ihmemies posted:I had to add Kits > Compilers > a manual compiler with flag like -ansi or -std=c90. Then use that Kit in the Qt project. Are you allowed to rearrange it?
|
# ? Jan 15, 2023 17:53 |
|
Loops aren’t required to cover the entire array. Think about how you’d write a loop that just walks the start of the array, or the end of it, or visits every other element. Then think about how you might use those things here.
|
# ? Jan 15, 2023 18:09 |
|
I ended up traversing the list yet again. If the same number was in the list before the current position, there was no need to print it again. Anyways, I made this truly awful solution to print correct amount of separators ',' between the words. Is there.. some better way to do this... this is horrible... The program tells to what limits the given number fits. Printout is something like this: code:
C code:
Ihmemies fucked around with this message at 17:35 on Jan 17, 2023 |
# ? Jan 17, 2023 17:31 |
|
Try printing separators before items.
|
# ? Jan 17, 2023 18:08 |
|
rjmccall posted:Try printing separators before items. At this rate I never will be a good enough at coding.
|
# ? Jan 17, 2023 18:10 |
|
Ihmemies posted:
It's a long journey of banging your head on practical things like that and then eventually gluing all those little tricks you've learned into functional-enough code in whatever language you happen to be using at the time.
|
# ? Jan 17, 2023 18:19 |
|
You can also avoid having to copy-paste that code for every separate type by separating it out into a function or a loop body. In the case of a loop you'd need to put all your min/max bounds and strings-to-print into a hard-coded array of some kind. Not a huge deal with only 5 options but if you are gonna modify that code later to add the rest of the C integer types it would be a lot easier without the code duplication
|
# ? Jan 17, 2023 18:28 |
|
Ihmemies posted:
Just try not to make the same mistake twice and you'll be a pro in no time.
|
# ? Jan 17, 2023 18:46 |
|
I made a struct for storing one entry, and added the structs to a struct array... never used these before I think, but at least it works!C code:
|
# ? Jan 17, 2023 20:01 |
|
A small nitpick/hint, but you can automatically calculate the MAX_LIMITS based on the sizeof of the limits array (since it's statically allocated). That way it's more tightly coupled with it, which is what you want (you won't have to remember to change two places at once).
|
# ? Jan 17, 2023 21:29 |
|
Thanks, I will do that too. It is a school exercise but I guess I can make it suck less, just to learn more. Only a machine will look at the code.
|
# ? Jan 17, 2023 22:30 |
|
Are there some resources somewhere on how could one use Boost ASIO ssl::stream with TLS-PSK? There was a patch submitted to Boost about 10 years ago, which was not accepted since it had a number of issues, but otherwise google is quite helpless in this regard. Thank you.
|
# ? Jan 21, 2023 03:38 |
|
Volguus posted:Are there some resources somewhere on how could one use Boost ASIO ssl::stream with TLS-PSK? There was a patch submitted to Boost about 10 years ago, which was not accepted since it had a number of issues, but otherwise google is quite helpless in this regard. Thank you. Calling native_handle() on your ssl::context will let you get to the underlying SSL_CTX from OpenSSL. Then, you can use SSL_CTX_set_psk_client_callback() (or one of the new find-session variants) to register a callback for providing PSKs. When OpenSSL does its negotiations, it'll call your callback to find and provide a PSK. The rejected patch is just making the old app-based version of that call and wrapping it in Boost idioms.
|
# ? Jan 21, 2023 07:15 |
|
ullerrm posted:Calling native_handle() on your ssl::context will let you get to the underlying SSL_CTX from OpenSSL. Then, you can use SSL_CTX_set_psk_client_callback() (or one of the new find-session variants) to register a callback for providing PSKs. When OpenSSL does its negotiations, it'll call your callback to find and provide a PSK. That's what I'm trying ... yet, I'm missing something. Here's the simplest server: C++ code:
C++ code:
I tried ALL as ciphers list. Same thing. I obviously have no idea how to even approach this, what exactly am I missing here. The callbacks are not called in either server or client, so I'm wondering if there's more setup that I need to do. Volguus fucked around with this message at 07:51 on Jan 21, 2023 |
# ? Jan 21, 2023 07:48 |
|
Got it working, that is, the client and the server exchange data as expected. There are a number of lessons I've learned and still a few questions. 1. I do have to call handshake (duh) 2. On the server side, if I want to set the callback (SSL_set_psk_server_callback) on the socket and not on the context, I have to set it on the client's socket, the one that I receive after calling accept. Makes sense now. Or just set the callbacks on the context and not worry about it. 3. If I want to use the new API (set_psk_find_session_callback and set_psk_use_session_callback ) either on the context or on the socket I still have to use the old APIs. Without it, the handshake fails. I have no idea why. The old callbacks do not get called, however. From the documentation (and from your previous post) it seems that I could use either, the new would replace the old, but in practice it doesn't seem to be the case (or, again, I'm making some dumb mistake). Getting inspiration from the official openssl application (server and client) it looks like they're getting the cipher to use in the new API via C code:
The callbacks for the new APIs seem a bit strange, not sure what's the advantage over the old ones, especially since it seems that I still have to define and set the old callbacks.
|
# ? Jan 21, 2023 19:50 |
|
|
# ? Jun 7, 2024 07:52 |
|
I'm about to walk into a forest of rakes on the ground in some code using Boost asio. It has a bunch of leaks in it, which makes me think the implementation isn't cleanly shutting it down properly. Are there some directions or patterns on that in general? In the past without other coroutine engines, I've seen various goofy ways to do it like scheduling a termination coroutine as an example, so I don't think it's going to be trivial.
|
# ? Jan 27, 2023 18:54 |