|
Is a difficulty a number that can meaningfully be incremented? Or a discrete bag of possible states? If incrementing it is actually meaningful, you might want to use an int or uint8_t or whatever. This library is cool: https://github.com/aantron/better-enums Also easy troll but I am triggered by m_ followed by a capital letter.
|
# ¿ Jul 1, 2017 04:47 |
|
|
# ¿ Apr 27, 2024 19:30 |
|
You might want to try out clang as a replacement compiler. Even if you still mainly use g++, running it through clang when you get a tough error might help - I know they've put a lot of effort into that.
|
# ¿ Jul 5, 2017 21:12 |
|
Can you pass a token when you register for the callback that you get back when it's called? That's often has these sorts of libraries let you do things like that, but I've never used this one. EDIT: Oh, just remove the &, method is already a pointer. The above matters if the same callback function is used in multiple places, like they're nested or something and only slow in some cases. If the function address is enough, it's just your types that are wrong. Jeffrey of YOSPOS fucked around with this message at 23:15 on Aug 3, 2017 |
# ¿ Aug 3, 2017 23:06 |
|
b0lt posted:Member function pointers are not regular pointers. On many ABIs, they're a struct that has a vtable offset and a this pointer offset. Oh ugg...it didn't occur to me that it was a member function pointer. Presumably he doesn't care which instance? Isn't this a C API which needs a proper function pointer? Maybe that's just always gonna be his thunk....ugg. I don't think the token would require patching all over the place, at least not if libev itself supports it. Log a backtrace and the id whenever something registers for a callback, print the id in the same place you call gettimeofday. At the end of the day, you have the value you need, in the worst case you can print it byte by byte in a union with a character array, or as two pointers if that's right. Nonportable but...I don't think that matters in this case. Jeffrey of YOSPOS fucked around with this message at 23:54 on Aug 3, 2017 |
# ¿ Aug 3, 2017 23:47 |
|
I assumed the software wasn't easy to just run your own personal instance of, which is why he didn't want to do hacky poo poo like turn off -Werror for his debug build.
|
# ¿ Aug 4, 2017 16:11 |
|
underage at the vape shop posted:It throws errors at me
|
# ¿ Sep 14, 2017 15:47 |
|
Can you post your code? It's hard to tell from just that though maybe I just don't remember common scanf pitfalls.
|
# ¿ Sep 23, 2017 09:23 |
|
Subjunctive posted:Why do they even let beginners use C?
|
# ¿ Sep 23, 2017 18:20 |
|
C is like portable machine code. The, uhh, register allocator isn't a good intro lesson I'm afraid.
|
# ¿ Sep 23, 2017 18:42 |
|
Array types have a few niche uses, I know you can use them if you wanna treat a single block of memory as a 2d array. (Cast a pointer to a pointer to an array of one dimension, index it with two indices to read it as an array.)
|
# ¿ Oct 26, 2017 22:54 |
|
rjmccall posted:Parameters declared to have array type are always actually pointers, regardless of whether the array has a bound. The bound is completely meaningless unless, in C99, the bound is declared as static (nobody knows you can do this), in which case it's a guaranteed (on pain of U.B.) lower bound on the size of the array.
|
# ¿ Oct 27, 2017 17:59 |
|
Pointers to arrays are cool. You can't dynamically allocate 2d arrays unless you either use them or are okay with an extra layer of indirection.
|
# ¿ Oct 27, 2017 20:37 |
|
Indeed - also NULL is a pointer-sized binary 0. (Not sure if this is actually platform-dependent but, anywhere that counts.)
|
# ¿ Oct 28, 2017 20:56 |
|
Is rolling your own pool allocator really all that different from using malloc? What is the purpose of the restriction?
|
# ¿ Nov 1, 2017 20:25 |
|
xgalaxy posted:Fun fact: Like...the big outstanding question is really just "what happens when you free an object?" in the context of doom 3. They have to keep track of which of their objects have been allocated already, and which ones are given back. That is, unless you can't free at all and they have a hard cap on the max number of objects of a given type that can be allocated. EDIT: Not saying pool allocating isn't useful - it's faster if you only have a few object types than fully-general allocation, and maybe you can pre-run some of your constructors and all that, at least the first time, and it likely will reduce fragmentation, but....it's still just a dynamic allocator. I could see that last one being a big issue for old-school doom when machines were quite memory-limited. If the reason you aren't allowed to malloc is that it can fail at runtime and you're writing code that really can't fail, you're committing a serious error by writing your own dynamic allocator and using that to work around it. You're still going to crash when you run out of space and fail to handle that case, and you're probably not going to do as good a job as the libc authors at doing so gracefully. Jeffrey of YOSPOS fucked around with this message at 23:29 on Nov 1, 2017 |
# ¿ Nov 1, 2017 22:54 |
|
roomforthetuna posted:Ehhh, if you're running alongside other things then allocating your own space at startup that's as big as you'll ever use is more resilient to mid-run failure than dynamic allocation that can fail because some other program ate all the memory. I don't think these cases are that different. You still have to check for and handle failure at each place that you do your allocation. At least on linux, you can tell malloc not to give memory back to the system with a simple toggle option, and preallocate that way. Then you don't have to bother writing your own object pool allocator with a free list or whatever unless you need the latency or lack of fragmentation it would provide. (Both versions can still fail due to over-commitment and paging to disk. There is almost certainly some way to turn this off on a system level but it may not be up to your program.)
|
# ¿ Nov 2, 2017 00:42 |
|
xgalaxy posted:Every game I've worked on thats been in C/C++ uses some form of linear allocators aka bump allocators almost throughout the entire code base. You can have one or several that exist for a frame, some that exist for a level or scene, etc. It scopes the life time of objects allocated from those things to those specific life times. "Allocating" from these and "Freeing" from these are markedly faster than using new/malloc & delete/free. No comparison in speed really. In triple AAA you would be stupid not to be using these. Indie games.. who gives a poo poo, you won't be stressing the system on those kinds of games.
|
# ¿ Nov 2, 2017 01:16 |
|
Rocko Bonaparte posted:The issue is speed in emulation. Doing a dynamic memory allocation increases the run time by orders of magnitude, and turns seconds into minutes, compounded hundreds of times. Yeah a state could just be an enum and you could have a static array indexed by it if you needed to. My point was really that you should try and find ways to genuinely not need a variable amount of memory, not try to work around it by writing your own Technically Not Malloc. I'm not disputing the value of pool allocators for other reasons but it's not what I think of as avoiding dynamic allocation. That alternative scheme is more what I had in mind if that is the goal.
|
# ¿ Nov 2, 2017 02:43 |
|
Twerk from Home posted:I'm taking over maintenance of a small C++ codebase, and it doesn't have an internally consistent code style. I've used JIndent previously for Java codebases, and am a big fan of Prettier on the js side.
|
# ¿ Nov 14, 2017 07:04 |
|
this is america, speak ascii
|
# ¿ Nov 19, 2017 00:45 |
|
You could do:code:
Jeffrey of YOSPOS fucked around with this message at 22:11 on Dec 5, 2017 |
# ¿ Dec 5, 2017 18:49 |
|
Xeom posted:If I have a pointer pointing to an element in a struct can I then access the struct in some way? Trying to understand the way the Linux kernel does linked lists. As far as I understand, it embeds the nodes into the data types themselves, and the nodes just point to other nodes. Yes - this is how linux does it. Your list_head is at a fixed offset into the struct, so if you have a pointer to one, you know it's offset and can subtract that and get the struct itself. Let's assume this list. code:
code:
Jeffrey of YOSPOS fucked around with this message at 01:58 on Dec 6, 2017 |
# ¿ Dec 5, 2017 21:30 |
|
Do you actually make use of values greatly different in magnitude or would fixed point suffice for your code? No worries if it's gotta be completely generic but that's definitely an option in some use cases.
|
# ¿ Dec 14, 2017 06:04 |
|
I'd want to know if they used something that was more "out there" but yeah, sounds like something you just learn per-project. C++ isn't something many industries pick by default any more and the ones who do generally have a specific purpose for it in mind which may well dictate the toolchain used.
|
# ¿ Dec 18, 2017 19:25 |
|
Love Stole the Day posted:So then what do you guys put on your resumes for prior experience? It seems easier to make a resume for getting into Web Development, where you just have to make something using an in-demand library/tool and then apply to jobs that have it in their job requirements. Here, it seems like there's nothing to demonstrate knowledge or experience with... other than prior experience...
|
# ¿ Dec 18, 2017 23:11 |
|
Love Stole the Day posted:Sure this makes sense for what to do during phone interviews, but I was actually asking about what comes before that point: specifically, what you put on that resume to actually get to that phone interview. Do you just put "C++" on your resume and then you hope that you don't get Black Hole'd so that you can actually talk to a human being about your experience with the language? Talk about projects that you've done using C++ and you can say specifically "in C++" in the description if you'd like. I look for a cluster of related things including not only the language C++ but also low-level computer systems knowledge in general. If I were instead at a game company I might look for game programming projects instead. I don't know how it works at really big companies but our resume screeners read the project descriptions and aren't just looking for keywords.
|
# ¿ Dec 18, 2017 23:48 |
|
Definitely clarify more than that - do you want to end up with an n by 2 array? Maybe say what domain this is for? How is the 2d array going to be used? I kinda feel like that's the sort of thing that you ought to figure out how to piece together on your own, it's trivial if you know how things work and dangerous if you don't. Any reason not to loop through and copying wouldn't work.
|
# ¿ Jan 5, 2018 22:51 |
|
Arrays are prove to out of bounds errors, my concern would be that you'd be given a firm rigid way of doing something, and only learn to manipulate that without understanding it. I see C as somewhat portable assembly language and is hard for me to think of it as a language whose abstractions I can trust without knowing how they work all the way. So like, I suspect some XY problem here - what are you trying to store in a 2d array? How many values are you storing? 20 or 100 are both reasonable answers but you should be able to answer before you write any code. If you want points on a n by n coordinate grid you want array[n][n]. If you want two arrays of size n, you could use an array[10][2], but I'd probably just use two arrays instead. It might be easier to post a (small) snippet of code and how it's defying expectations if you've already written something.
|
# ¿ Jan 6, 2018 02:42 |
|
*lifts up shirt to show battle scars, man boobs* this is my certification
|
# ¿ Jan 6, 2018 03:40 |
|
I think it will hurt performance if you use it as a drop in replacement if you ever copy them by value and rely on c arrays degrading to pointers in those cases. If you are writing new code, you can explicitly pass references or pointers around when you want them.
|
# ¿ Jan 8, 2018 03:44 |
|
The line:code:
code:
The thing I was unclear on was what you meant by "combine two arrays". Being precise matters here because there are 11 ways I can imagine to combine arrays and most of them don't result in a 2d array that's nxn for two size n arrays. I don't really even see what you're combining here, you didn't have arrays to begin with either, you created them to store x coordinates and then y coordinates only to then use those to fill in a 2d array. There's a few things going on there - for one, you could potentially skip the middle man, and just use rand() % 10 with the 2d array, something like this: code:
code:
|
# ¿ Jan 10, 2018 01:50 |
|
Reading and writing to those fields will generate instructions that will mask off only those bits and read/write to them. The bit order within memory is compiler-dependent though, so don't rely on it for a network protocol or something. (In practice if you only have one platform it's probably fine - I'm sure this example is that case given that it's .) So 8 bits will be used for the addr bitfield, that could just be a uint8_t itself. 21 bits are used reserved and not for you to use - nothing you write using this struct will set those bits no matter what. 1 bit is used for the retry field - reading from it will return 1 or 0. You have to know more about the iic protocol to use it I think but yeah, that looks like a fine message header struct/bitfield example to me.
|
# ¿ Jan 22, 2018 05:37 |
|
Yeah the compiler will generate code to do the shifting and write to just those bits. You can just write 1 to nostart. The reason people stick typedefs around structs is so they can declare them with one identifier - in the future you can declare one with just "iic_transfer foo;" instead of "struct iic_header foo;" because you have the typedef around it. It's basically saying "create an alias for struct iic_transfer { unsigned bunchofthings:69; } called iic_transfer.
|
# ¿ Jan 22, 2018 07:53 |
|
Also the comment says this:code:
|
# ¿ Jan 22, 2018 07:58 |
|
please use -fno-strict-aliasing
|
# ¿ Jan 25, 2018 04:54 |
|
Interpreting a sequence of bytes as a struct is like, C's core competency and gently caress if I'm gonna use a union to do it!!!
|
# ¿ Jan 25, 2018 05:04 |
|
Xarn posted:No. Use memcpy.
|
# ¿ Jan 25, 2018 16:38 |
|
eth0.n posted:Casting a pointer to char to a pointer to a struct is not a violation of strict aliasing. This is not where memcpy is needed. Alignment is an issue on some platforms. GCC aligned types and attribute packed can help here, but yeah, the compiler will happily convert "aligned pointers" to normal unconstrained pointers without warning by default, so being careful when using those is warranted. In general you should know your own platform here and minimize unaligned accesses but trying to eliminate them completely is pretty extreme if you're, say, handling a network protocol that sends unaligned integers as part of normal operation.
|
# ¿ Jan 25, 2018 17:54 |
|
The behavior isn't undefined if your compiler defines how it will behave - conforming to ISO C in this case makes your code worse, not better. My real answer is that I agree with Linus that, while I understand how the aliasing rules came to be, I think they are boneheaded as written and ought to be worked around if you need to view the same memory in multiple ways. They could have specified the language such that the degradation of aliasing assumptions could be controlled by the user, but they didn't bother doing that. The ISO C spec is not a religious text, you're allowed to question it and I think it'd be irresponsible to manage any large C project without at the very least thinking carefully about discarding the existing aliasing rules, especially if what you're doing involves receiving binary data from external sources. Casting between pointer types in your function is a good sign that the strict aliasing assumptions are not true within that function, my complaint pretty much would go away if the spec was written such that it gave up its aliasing assumptions once that happened.
|
# ¿ Jan 25, 2018 21:09 |
|
|
# ¿ Apr 27, 2024 19:30 |
|
Jabor posted:The fact that the "reinterpret the opaque sequence of bytes as a different type" function is called "memcpy" is an unfortunate historical oddity, but it still does what you're actually trying to accomplish in most cases.
|
# ¿ Jan 26, 2018 05:28 |