Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Private Speech
Mar 30, 2011

I HAVE EVEN MORE WORTHLESS BEANIE BABIES IN MY COLLECTION THAN I HAVE WORTHLESS POSTS IN THE BEANIE BABY THREAD YET I STILL HAVE THE TEMERITY TO CRITICIZE OTHERS' COLLECTIONS

IF YOU SEE ME TALKING ABOUT BEANIE BABIES, PLEASE TELL ME TO

EAT. SHIT.


Is there any way to exploit programs that do not not explicitly include stdlib.h? I can't really find anything about it but I heard you could.

Adbot
ADBOT LOVES YOU

Private Speech
Mar 30, 2011

I HAVE EVEN MORE WORTHLESS BEANIE BABIES IN MY COLLECTION THAN I HAVE WORTHLESS POSTS IN THE BEANIE BABY THREAD YET I STILL HAVE THE TEMERITY TO CRITICIZE OTHERS' COLLECTIONS

IF YOU SEE ME TALKING ABOUT BEANIE BABIES, PLEASE TELL ME TO

EAT. SHIT.


I know there's been some recent discussion about this, but what would be a good c++ IDE for linux? I'd just use VS but I only have a few weeks and I'd rather not deal with any portability issues (it's a compiler so there's bound to be some). My first instinct is to use eclipse since I like using it for java (netbeans might be better but whatever) and python. But I've heard it's really bad? I don't want to use sublime/vim/emacs because I want an actual IDE, not a glorified text editor.

Private Speech
Mar 30, 2011

I HAVE EVEN MORE WORTHLESS BEANIE BABIES IN MY COLLECTION THAN I HAVE WORTHLESS POSTS IN THE BEANIE BABY THREAD YET I STILL HAVE THE TEMERITY TO CRITICIZE OTHERS' COLLECTIONS

IF YOU SEE ME TALKING ABOUT BEANIE BABIES, PLEASE TELL ME TO

EAT. SHIT.


ExcessBLarg! posted:

The concern with shipping application and (L)GPL code together is whether either portion is really a derived work of the other, such as if the "library" code was heavily modified to support just that application. I think it's pretty defensible to ship a portion of KDE libraries as a convenience to having to ship and build the whole thing, especially if the application can be alternatively built with the full KDE frameworks library instead of the stub.

This is really the important bit, modifying LGPL libraries to support your specific use case is on legally very shaky ground (i.e. you might then have to license your application under LGPL because it's derived work). Even if they are done as separate projects.

Private Speech
Mar 30, 2011

I HAVE EVEN MORE WORTHLESS BEANIE BABIES IN MY COLLECTION THAN I HAVE WORTHLESS POSTS IN THE BEANIE BABY THREAD YET I STILL HAVE THE TEMERITY TO CRITICIZE OTHERS' COLLECTIONS

IF YOU SEE ME TALKING ABOUT BEANIE BABIES, PLEASE TELL ME TO

EAT. SHIT.


Being interviewed for a C++ position by an EE engineer with zero professional development experience in C++ was fun too. He had a list of question printed off the internet and about 5 minutes in I got the distinct impression that he only understands the parts of my replies that talk about differences between C99 and C++. You'd think he'd at least look up the correct answers to his own list.

Private Speech
Mar 30, 2011

I HAVE EVEN MORE WORTHLESS BEANIE BABIES IN MY COLLECTION THAN I HAVE WORTHLESS POSTS IN THE BEANIE BABY THREAD YET I STILL HAVE THE TEMERITY TO CRITICIZE OTHERS' COLLECTIONS

IF YOU SEE ME TALKING ABOUT BEANIE BABIES, PLEASE TELL ME TO

EAT. SHIT.


feedmegin posted:

Some of us program microcontrollers in plain old C :sun:

There's like 3 embedded developers posting in UKMT apparently? Weird.

I'm always happy when I get to play around with C++ to write a random desktop tool or whatever.

Private Speech
Mar 30, 2011

I HAVE EVEN MORE WORTHLESS BEANIE BABIES IN MY COLLECTION THAN I HAVE WORTHLESS POSTS IN THE BEANIE BABY THREAD YET I STILL HAVE THE TEMERITY TO CRITICIZE OTHERS' COLLECTIONS

IF YOU SEE ME TALKING ABOUT BEANIE BABIES, PLEASE TELL ME TO

EAT. SHIT.


We've been using Make instead of CMake for some modules we compile against the Linux kernel. As far as I can see there is no reasonable way to do this without Make, as the kernel uses autotools+make itself.

I suppose you could make a fake compiler which would actually be a Make call, but a) we already have to do this because the kernel compilation process requires it anyway, and b) Make already does recursive Make better than any other tool I can think of.

Private Speech
Mar 30, 2011

I HAVE EVEN MORE WORTHLESS BEANIE BABIES IN MY COLLECTION THAN I HAVE WORTHLESS POSTS IN THE BEANIE BABY THREAD YET I STILL HAVE THE TEMERITY TO CRITICIZE OTHERS' COLLECTIONS

IF YOU SEE ME TALKING ABOUT BEANIE BABIES, PLEASE TELL ME TO

EAT. SHIT.


Zerf posted:

Been a long time since I used CMake, but I think using other build systems from CMake is supported through ExternalProject_Add (https://cmake.org/cmake/help/v3.11/module/ExternalProject.html)

Googling around for CMake and Linux Kernel I found this, but honestly by that point it seems easier to use Make; for one it's about half of that size, and that's with a more complicated compilation pathway.

Private Speech
Mar 30, 2011

I HAVE EVEN MORE WORTHLESS BEANIE BABIES IN MY COLLECTION THAN I HAVE WORTHLESS POSTS IN THE BEANIE BABY THREAD YET I STILL HAVE THE TEMERITY TO CRITICIZE OTHERS' COLLECTIONS

IF YOU SEE ME TALKING ABOUT BEANIE BABIES, PLEASE TELL ME TO

EAT. SHIT.


Foxfire_ posted:

The right answer is to talk about C++ features that are unsuitable for various sizes of microcontrollers, how you would deal with the problems that those kinds of things were intended to solve (in either C or C++ that disallows them), talk some about externality stuff (toolchain, portability, programmer knowledge, ...)

Basically show off that you understand what you're doing and can make good design choices. You're in a conversation trying to show that you're competent; it's not a multiple choice test with only one answer.

To be honest I would say that for the kind of people who ask that question C is the only right answer 90% of the time - it could even very well be that they themselves do not have much (or any) knowledge of C++. I certainly know several embedded developer from CSE/EE backgrounds who don't.

I tend to use C++ for our desktop-side applications instead of C, and I do get slight disapproval even if it is far more suited to the task (writing GUI-based applications in C is just painful), even if the people I currently work with do know C++ to a reasonable extent. If I wasn't working at a startup I imagine I wouldn't be allowed to do so.

The code-memory correspondence is a pretty big one too; I find that with custom linker scripts it makes it easier to implement multi-stage flashing/recovery code segments which have to exist in a single page of memory.

Private Speech
Mar 30, 2011

I HAVE EVEN MORE WORTHLESS BEANIE BABIES IN MY COLLECTION THAN I HAVE WORTHLESS POSTS IN THE BEANIE BABY THREAD YET I STILL HAVE THE TEMERITY TO CRITICIZE OTHERS' COLLECTIONS

IF YOU SEE ME TALKING ABOUT BEANIE BABIES, PLEASE TELL ME TO

EAT. SHIT.


Azuth0667 posted:

I've been trying to get GTK to work with code:blocks but, it seems that every error I fix results in new errors popping up. Is there a better way to set up GTK for C other than going through MSYS2 to get GTK?

I've used MSYS GTK at work and it's not that bad, but you do end up with a buttload of DLLs. I didn't find it particularly hard to set up.

Private Speech
Mar 30, 2011

I HAVE EVEN MORE WORTHLESS BEANIE BABIES IN MY COLLECTION THAN I HAVE WORTHLESS POSTS IN THE BEANIE BABY THREAD YET I STILL HAVE THE TEMERITY TO CRITICIZE OTHERS' COLLECTIONS

IF YOU SEE ME TALKING ABOUT BEANIE BABIES, PLEASE TELL ME TO

EAT. SHIT.


SYSV Fanfic posted:

Can you not just compile a single file to an object without optimization then link it in when you compile the rest of it?

It makes no difference, the optimisation is done inside the CPU itself.

e: I assumed you were talking about ILP and instruction reordering there. It would probably work for the AVR, but volatile should be fine in that case and it won't interfere with other optimisations you might want to happen.

Private Speech fucked around with this message at 20:29 on Jan 9, 2019

Private Speech
Mar 30, 2011

I HAVE EVEN MORE WORTHLESS BEANIE BABIES IN MY COLLECTION THAN I HAVE WORTHLESS POSTS IN THE BEANIE BABY THREAD YET I STILL HAVE THE TEMERITY TO CRITICIZE OTHERS' COLLECTIONS

IF YOU SEE ME TALKING ABOUT BEANIE BABIES, PLEASE TELL ME TO

EAT. SHIT.


e: nm, was an anecdote about it being really hard to track down but maybe I shouldn't post the details.

Private Speech fucked around with this message at 03:51 on Jan 10, 2019

Private Speech
Mar 30, 2011

I HAVE EVEN MORE WORTHLESS BEANIE BABIES IN MY COLLECTION THAN I HAVE WORTHLESS POSTS IN THE BEANIE BABY THREAD YET I STILL HAVE THE TEMERITY TO CRITICIZE OTHERS' COLLECTIONS

IF YOU SEE ME TALKING ABOUT BEANIE BABIES, PLEASE TELL ME TO

EAT. SHIT.


Reminds me of the glorious geeksforgeeks quizzes which are apparently used for recruiting developers in India. Couple examples:

code:
What is printed by the following C program?

#include <stdio.h>
int f(int x, int *py, int **ppz)
{
  int y, z;
  **ppz += 1; 
   z  = **ppz;
  *py += 2;
   y = *py;
   x += 3;
   return x + y + z;
}
  
void main()
{
   int c, *b, **a;
   c = 4;
   b = &c;
   a = &b; 
   printf( "%d", f(c,b,a));
   getchar();
}
code:
What is printed by the following C program?

#include <stdio.h>
 
char *c[] = {"GeksQuiz", "MCQ", "TEST", "QUIZ"};
char **cp[] = {c+3, c+2, c+1, c};
char ***cpp = cp;
 
int main()
{
    printf("%s ", **++cpp);
    printf("%s ", *--*++cpp+3);
    printf("%s ", *cpp[-2]+3);
    printf("%s ", cpp[-1][-1]+1);
    return 0;
}
e: It's actually quite fun to do but, uhh, no that's not code I ever want to read or write at work.

Private Speech fucked around with this message at 16:42 on Mar 28, 2019

Private Speech
Mar 30, 2011

I HAVE EVEN MORE WORTHLESS BEANIE BABIES IN MY COLLECTION THAN I HAVE WORTHLESS POSTS IN THE BEANIE BABY THREAD YET I STILL HAVE THE TEMERITY TO CRITICIZE OTHERS' COLLECTIONS

IF YOU SEE ME TALKING ABOUT BEANIE BABIES, PLEASE TELL ME TO

EAT. SHIT.


Yeah basically just linker magic, it's common to have significant amount of linker tweaks on RTOS/MCU embedded platforms (unix ones not so much).

Even more fun is when you have two interrupt vectors for the purpose of firmware flashing, and you have to swap them.

e: Or, well, firmware flashing in general is quite fun, since the flash tends to be only writable in pages and there's all sorts of fun to be had there. Especially if you don't have enough space to keep two copies of the program active at once (you write a minimalist flashing routine first, then swap into that, overwrite the main program, and then swap back).

Private Speech fucked around with this message at 06:02 on Mar 8, 2020

Private Speech
Mar 30, 2011

I HAVE EVEN MORE WORTHLESS BEANIE BABIES IN MY COLLECTION THAN I HAVE WORTHLESS POSTS IN THE BEANIE BABY THREAD YET I STILL HAVE THE TEMERITY TO CRITICIZE OTHERS' COLLECTIONS

IF YOU SEE ME TALKING ABOUT BEANIE BABIES, PLEASE TELL ME TO

EAT. SHIT.


taqueso posted:

What is a good modern C++ guide?

CppCoreGuidelines or the Google C++ style guide?

Ones I have bookmarked anyway.

Private Speech
Mar 30, 2011

I HAVE EVEN MORE WORTHLESS BEANIE BABIES IN MY COLLECTION THAN I HAVE WORTHLESS POSTS IN THE BEANIE BABY THREAD YET I STILL HAVE THE TEMERITY TO CRITICIZE OTHERS' COLLECTIONS

IF YOU SEE ME TALKING ABOUT BEANIE BABIES, PLEASE TELL ME TO

EAT. SHIT.


more falafel please posted:

"Embedded ARM device" could mean a lot of things, is there an OS with file permissions? Is the program running at elevated privilege with respect to the user? Because my first thought is to use chmod to make the file readable only by the user that the program runs as.

Pretty sure he's asking about a DRM implementation, so simply blocking other processes from accessing a plaintext file may not work terribly well for a number of reasons. Doesn't seem anywhere as secure as what he's proposing in the first place, might be a reasonable extra to include though.

Anyway the described system sounds more than secure enough by embedded standards. There hasn't been an unbreakable DRM scheme where the hardware is in customer hands designed so far, not even by the likes of Sony, Nintendo and Microsoft throwing hundreds of millions and ASICs at it, so you probably won't design one either.

e: Or if it's an especially valuable high-volume item do what everyone else does and make a security dongle, or hire a team and spend a lot of money on it. But that's very much a cost-benefit problem at that point.

Private Speech fucked around with this message at 01:20 on May 17, 2020

Private Speech
Mar 30, 2011

I HAVE EVEN MORE WORTHLESS BEANIE BABIES IN MY COLLECTION THAN I HAVE WORTHLESS POSTS IN THE BEANIE BABY THREAD YET I STILL HAVE THE TEMERITY TO CRITICIZE OTHERS' COLLECTIONS

IF YOU SEE ME TALKING ABOUT BEANIE BABIES, PLEASE TELL ME TO

EAT. SHIT.


I wrote a longish answer before changing my mind, but the gist of it was that a) I haven't use the OpenSSL API myself, sorry, and b), how do you prevent someone from just no-op cracking your thing if they are savvy enough to use gdb to find the license key.

Either way having played around with reverse-engineering in IDA myself the answer mostly seems to be obfuscation and "executable packing", i.e. encrypting the executable itself - that might be what you want to look up. I haven't implemented it either though, sorry.

Hopefully someone else can help better.

Private Speech fucked around with this message at 02:21 on May 17, 2020

Private Speech
Mar 30, 2011

I HAVE EVEN MORE WORTHLESS BEANIE BABIES IN MY COLLECTION THAN I HAVE WORTHLESS POSTS IN THE BEANIE BABY THREAD YET I STILL HAVE THE TEMERITY TO CRITICIZE OTHERS' COLLECTIONS

IF YOU SEE ME TALKING ABOUT BEANIE BABIES, PLEASE TELL ME TO

EAT. SHIT.


Absurd Alhazred posted:

As if I'd contaminate my local namespaces with std junk. :smugdog:

that's why you do "using std::uint32_t" smh

As far as the post above mine goes I recommend watching the talk about const-correctness (named "const as a promise") by Ben Saks at cppcon, it's on youtube.

He spends about an hour explaining why that's wrong and top-level consts are bad.

I'm not saying he's right or wrong but it's definitely a sentiment that's somewhat popular and worth being aware of for interviews and such.

Private Speech fucked around with this message at 11:53 on Apr 4, 2021

Private Speech
Mar 30, 2011

I HAVE EVEN MORE WORTHLESS BEANIE BABIES IN MY COLLECTION THAN I HAVE WORTHLESS POSTS IN THE BEANIE BABY THREAD YET I STILL HAVE THE TEMERITY TO CRITICIZE OTHERS' COLLECTIONS

IF YOU SEE ME TALKING ABOUT BEANIE BABIES, PLEASE TELL ME TO

EAT. SHIT.


It's specifically about top-level consts in function arguments/parameters, but now I'm trying to think if it has any implications there w.r.t. space optimisation.

Top-level meaning const pointer rather than pointer-to-const, which he's very much in favour of.

e: i.e.. void foo(bar *const baz) rather than foo(const bar *baz) or foo(bar const *baz), with the first being bad

Private Speech fucked around with this message at 12:46 on Apr 4, 2021

Private Speech
Mar 30, 2011

I HAVE EVEN MORE WORTHLESS BEANIE BABIES IN MY COLLECTION THAN I HAVE WORTHLESS POSTS IN THE BEANIE BABY THREAD YET I STILL HAVE THE TEMERITY TO CRITICIZE OTHERS' COLLECTIONS

IF YOU SEE ME TALKING ABOUT BEANIE BABIES, PLEASE TELL ME TO

EAT. SHIT.


Xarn posted:

If that's your take-away, you either misunderstood the talk, or my post. The trick is that your declaration looks like this

Here he's talking about top-level const specifically:

https://www.youtube.com/watch?v=NZtr93iL3R0&t=2876s

Again very unambiguous, to quote the slides "Avoid using const at the top level of parameter declarations". (note he means definition by your language here, as can be clearly seen from the slides)

(formatting replicated from the slides)

Or to quote the talk "My position, my advice is, this is, regard this as useless."


e: removed the first link for clarity, since the second directly addresses it

Private Speech fucked around with this message at 18:49 on Apr 4, 2021

Private Speech
Mar 30, 2011

I HAVE EVEN MORE WORTHLESS BEANIE BABIES IN MY COLLECTION THAN I HAVE WORTHLESS POSTS IN THE BEANIE BABY THREAD YET I STILL HAVE THE TEMERITY TO CRITICIZE OTHERS' COLLECTIONS

IF YOU SEE ME TALKING ABOUT BEANIE BABIES, PLEASE TELL ME TO

EAT. SHIT.


qsvui posted:

I'm with Xarn on this one, the example Dan uses isn't convincing at all:
C++ code:
void *memcpy(void *d, void const *s, size_t n) {
    ~~~
    for (; n > 0; --n, ~~~) {   // OK
        ~~~
    }
    return d;
}
Dan goes on to say if you make n const, it would invalidate this programming style. Ok... then don't use const for this particular case??? Because you clearly mean that n can (and will) be modified here. But feel free to use const for all the other arguments you won't be touching.

He also goes through a few more points and examples against it earlier in the talk, but that's mainly for const pointers specifically (not pointer-to-const, const pointers). In particular that you can break that specific constness in a few ways.

In general I can understand both sides of the argument, but I feel like it's worth acknowledging both styles as valid and reasonable. I personally prefer not to use top-level const arguments for much the same reason he gives, but I can see why it can be marginally useful as a protective measure.

As I said in my first post on the topic it's more being aware of why some people might prefer not to use it can be worthwhile for interviews etc.

Private Speech fucked around with this message at 01:38 on Apr 5, 2021

Private Speech
Mar 30, 2011

I HAVE EVEN MORE WORTHLESS BEANIE BABIES IN MY COLLECTION THAN I HAVE WORTHLESS POSTS IN THE BEANIE BABY THREAD YET I STILL HAVE THE TEMERITY TO CRITICIZE OTHERS' COLLECTIONS

IF YOU SEE ME TALKING ABOUT BEANIE BABIES, PLEASE TELL ME TO

EAT. SHIT.


Winter Stormer posted:

I would agree that it shouldn't go on the declaration in your header file
pre:
// lib.h
int g(int a);
int g(const int a); // Equivalent but noisier -- 
                    // neither constrains the constness of a in the definition
but there's no reason not to use const in the definition if you don't plan to change that variable in the function body and want to make it clear (or enlist the compiler's help in enforcing that).

As I said, and as is obvious from the video, he uses the word declaration as definition there. He's a member of various committees and working groups so you'd think he would use the standard terminology but there.

And I think the argument is that you should not put const there because a) const on local variable has a different meaning w.r.t. emitted code, and, primarily, b), that it makes it hard to read at a glance if you need to pass it a const argument or not.

Private Speech fucked around with this message at 12:12 on Apr 5, 2021

Private Speech
Mar 30, 2011

I HAVE EVEN MORE WORTHLESS BEANIE BABIES IN MY COLLECTION THAN I HAVE WORTHLESS POSTS IN THE BEANIE BABY THREAD YET I STILL HAVE THE TEMERITY TO CRITICIZE OTHERS' COLLECTIONS

IF YOU SEE ME TALKING ABOUT BEANIE BABIES, PLEASE TELL ME TO

EAT. SHIT.


I do agree with him, pretty much for the same reasons he gives. And I don't think I'm alone in that, seeing as I'm not even the person to start this argument (that being rjmccall).

Also worth noting that the standard library or indeed most other libraries and major OSS projects do follow the same rule.

e: It is also discouraged in Google C++ guidelines fwiw.

Core C++ guidelines does not explicitly discourage its use, but neither does it encourage as it does with other const and constexpr.

As for my personal reasoning - frankly if your functions get complex enough that you need to use const to make sure you don't use local copies of arguments in the wrong way, in the function you wrote, where declaring them so would have no effect on the outward behaviour - then, well, perhaps it's time to refactor that function.

Also, as far as a const object rather than primitive is concerned - why are you even passing by value instead of const reference in the first place - if it's a primitive I can maybe see a marginal niche for it, but seems a bit inefficient for an object even ignoring all the other reasons.

e2: Actually now that I think about it I can see the use case for primitives, where if you are passing them to other functions you want to make sure they also don't change them. But at least for objects and pointers I really don't see the point of making them const rather than using a const reference.

i.e.:

code:
void foo(const int& inp);
void bar(const int input) {
	foo(input);
}
would not compile if it were

code:
void foo(int& inp);
void bar(const int input) {
	foo(input);
}
which can be useful I suppose.

Private Speech fucked around with this message at 13:17 on Apr 5, 2021

Private Speech
Mar 30, 2011

I HAVE EVEN MORE WORTHLESS BEANIE BABIES IN MY COLLECTION THAN I HAVE WORTHLESS POSTS IN THE BEANIE BABY THREAD YET I STILL HAVE THE TEMERITY TO CRITICIZE OTHERS' COLLECTIONS

IF YOU SEE ME TALKING ABOUT BEANIE BABIES, PLEASE TELL ME TO

EAT. SHIT.


Okay fair enough, I was wrong about the "standard library" for some value of "standard library". Though I'm not sure if it applies equally to libstdc++ rather than Microsoft STL, which is what I had in mind, at a quick glance they don't seem to put const on top-level qualifiers - i.e., from fs_dir.cc in GCC libstdc++:

code:
  bool should_recurse(bool follow_symlink, error_code& ec) const
  {
    file_type type = entry._M_type;
    if (type == file_type::none)
    {
      type = entry.symlink_status(ec).type();
      if (ec)
	return false;
    }

    if (type == file_type::directory)
      return true;
    if (type == file_type::symlink)
      return follow_symlink && is_directory(entry.status(ec));
    return false;
  }

  fs::path		path;
  directory_entry	entry;
};
follow_symlink there could clearly be const, but it's not

Winter Stormer posted:

Xarn and rjmccall were not arguing what are you even on about lol

Maybe not arguing but either way it was brought up and I only posted why you might not want to use it.

At best I'd say it is bikeshedding and I personally don't think there's a meaningful advantage to it. Note that even while the guidelines don't explicitly prohibit it, they do say "according to their own judgement" which to me indicates that it is not the universally accepted thing to do.

Private Speech fucked around with this message at 15:44 on Apr 5, 2021

Private Speech
Mar 30, 2011

I HAVE EVEN MORE WORTHLESS BEANIE BABIES IN MY COLLECTION THAN I HAVE WORTHLESS POSTS IN THE BEANIE BABY THREAD YET I STILL HAVE THE TEMERITY TO CRITICIZE OTHERS' COLLECTIONS

IF YOU SEE ME TALKING ABOUT BEANIE BABIES, PLEASE TELL ME TO

EAT. SHIT.


Vargatron posted:

So lets say I'm reading values from a file into a struct, but I don't know how many values are in that file? Would I need to create a loop and the reallocate more memory each time the loop iterates? I've read a bit about the realloc() function in my textbook but we haven't really covered that in any exercises.

To be clear, we've just got finished covering pointers and File I/O so my experience level with C is fairly rudimentary.

Basically yes, if you can't get away with preallocating, look up dynamic arrays.

What you normally do is something like a doubling strategy with some sensible default allocation, wherein you allocate double the existing size of your array once you fill it up.

You can also potentially use a list or a hashmap or a tree or some other data structure, but then it may be even more difficult to do so correctly.

There's also a consideration to be made whether to store pointers to objects or the objects themselves.

e: This is one of the big things C++ frees you from, at least as long as you are okay with using the relatively inefficient default containers in STL.

Private Speech fucked around with this message at 21:23 on Apr 9, 2021

Private Speech
Mar 30, 2011

I HAVE EVEN MORE WORTHLESS BEANIE BABIES IN MY COLLECTION THAN I HAVE WORTHLESS POSTS IN THE BEANIE BABY THREAD YET I STILL HAVE THE TEMERITY TO CRITICIZE OTHERS' COLLECTIONS

IF YOU SEE ME TALKING ABOUT BEANIE BABIES, PLEASE TELL ME TO

EAT. SHIT.


I don't quite get how you can know enough to need to write cmake scripts but still not be able to figure it out.

Private Speech
Mar 30, 2011

I HAVE EVEN MORE WORTHLESS BEANIE BABIES IN MY COLLECTION THAN I HAVE WORTHLESS POSTS IN THE BEANIE BABY THREAD YET I STILL HAVE THE TEMERITY TO CRITICIZE OTHERS' COLLECTIONS

IF YOU SEE ME TALKING ABOUT BEANIE BABIES, PLEASE TELL ME TO

EAT. SHIT.


e: nm, a bit too YOSPOSy

Private Speech fucked around with this message at 16:56 on Oct 6, 2021

Private Speech
Mar 30, 2011

I HAVE EVEN MORE WORTHLESS BEANIE BABIES IN MY COLLECTION THAN I HAVE WORTHLESS POSTS IN THE BEANIE BABY THREAD YET I STILL HAVE THE TEMERITY TO CRITICIZE OTHERS' COLLECTIONS

IF YOU SEE ME TALKING ABOUT BEANIE BABIES, PLEASE TELL ME TO

EAT. SHIT.


Sweeper posted:

It’s not a vector of bool

This.

I mean the intention, i.e. to avoid inefficiency, was good. But the problem is it doesn't work like any other vector which breaks a lot of things that rely on standard vector behaviour.

You can just make a vector of bytes or something instead if you want it.

Private Speech fucked around with this message at 04:19 on Apr 24, 2022

Private Speech
Mar 30, 2011

I HAVE EVEN MORE WORTHLESS BEANIE BABIES IN MY COLLECTION THAN I HAVE WORTHLESS POSTS IN THE BEANIE BABY THREAD YET I STILL HAVE THE TEMERITY TO CRITICIZE OTHERS' COLLECTIONS

IF YOU SEE ME TALKING ABOUT BEANIE BABIES, PLEASE TELL ME TO

EAT. SHIT.


I think C is fine for embedded but C++ can be really nice. It depends - if you're writing tight, inline-assembly loops on constrained micros without rtos or writing linux kernel drivers then you don't really have a choice, but if neither of those things is on the cards C++ is much nicer to work with.

I think the industry as a whole is slowly adopting C++ more and more, especially as chips become more powerful and/or cheaper with time.

Private Speech
Mar 30, 2011

I HAVE EVEN MORE WORTHLESS BEANIE BABIES IN MY COLLECTION THAN I HAVE WORTHLESS POSTS IN THE BEANIE BABY THREAD YET I STILL HAVE THE TEMERITY TO CRITICIZE OTHERS' COLLECTIONS

IF YOU SEE ME TALKING ABOUT BEANIE BABIES, PLEASE TELL ME TO

EAT. SHIT.


frogge posted:

Should I bother with C++ or try learning something newer since I've basically forgotten it all? How would I get started with it?

I agree that a simple language might be a better starting point, but it's worth noting that C++ hasn't really been superseded yet, certainly not by Python or JS.

Well there's Rust but that's not simpler to learn by any means.

Private Speech
Mar 30, 2011

I HAVE EVEN MORE WORTHLESS BEANIE BABIES IN MY COLLECTION THAN I HAVE WORTHLESS POSTS IN THE BEANIE BABY THREAD YET I STILL HAVE THE TEMERITY TO CRITICIZE OTHERS' COLLECTIONS

IF YOU SEE ME TALKING ABOUT BEANIE BABIES, PLEASE TELL ME TO

EAT. SHIT.


Ihmemies posted:

Don’t worry. Next task is to implement a Book class with 16 mandatory methods, using pointers and recursion. The only choice is that I can use smart pointers instead of regular pointers if I want to. I have one week. :shepicide:

Once you understand how pointers work that's really not that much work at all, TBH. Even if you're new and having trouble you should be able to finish it in 2 afternoons or so.

Private Speech
Mar 30, 2011

I HAVE EVEN MORE WORTHLESS BEANIE BABIES IN MY COLLECTION THAN I HAVE WORTHLESS POSTS IN THE BEANIE BABY THREAD YET I STILL HAVE THE TEMERITY TO CRITICIZE OTHERS' COLLECTIONS

IF YOU SEE ME TALKING ABOUT BEANIE BABIES, PLEASE TELL ME TO

EAT. SHIT.


Computer viking posted:

C++ is a nifty expansion of C if you just limit yourself to the right parts. It can also be a fairly clean modern language if you just stick to those parts. The problem is that nobody agrees on which parts are the good ones, and you can't entirely avoid the rest.

I rarely reach for C++; if I want a low level language I'll stick to C, and if I want a modern language there are multiple alternatives that don't have more corner cases than a hedge maze. It's the best way to write Qt and fast R libraries, I guess?

(Why am I in this thread if I'm so ambivalent to C++? Idk, I like C and hope to absorb some C++ by immersion?)

I think this speaks more about your personal preferences and experience than any worth of C++ - for me it's the best language to use for almost anything that's not either bare metal, web/GUI-heavy or that can be done by a quick python script.

It does have some issues and a steep learning curve but I don't think there is any so-called "modern" systems language that is genuinely superior - sure if you need to do web/heavy GUI then there are languages in which you can do that much faster and if you need to work in a environment where you can't rely on a proper OS then C involves much less of "okay I can use these few bits but not the other 70% of normal C++", but for writing complex high-performance code there really isn't anything better.

Rust maybe comes close but it has that hobby language flavour to it.

Private Speech fucked around with this message at 03:10 on Apr 8, 2023

Private Speech
Mar 30, 2011

I HAVE EVEN MORE WORTHLESS BEANIE BABIES IN MY COLLECTION THAN I HAVE WORTHLESS POSTS IN THE BEANIE BABY THREAD YET I STILL HAVE THE TEMERITY TO CRITICIZE OTHERS' COLLECTIONS

IF YOU SEE ME TALKING ABOUT BEANIE BABIES, PLEASE TELL ME TO

EAT. SHIT.


BattleMaster posted:

Screaming into the void again, I'm doing some more stuff with io_uring. It has an opcode (IORING_OP_LINK_TIMEOUT added with io_uring_prep_link_timeout in liburing) has the ability to attach a timer to an entry being submitted that will cancel it if the timer ticks over before it's completed.

It works fine but the return value is useless and also not properly documented. It says it returns 0 on a success but there's no scenario where it returns 0. If no actual error happens, it returns -ETIME if the timeout occurred or -ECANCELED if the timeout was canceled because the attached entry completed first. Also, -ETIME means a cancellation is ATTEMPTED, not that the cancellation succeeded. So the only way to find out if the cancellation went through is to find the entry for the thing you wanted to cancel in the completion queue and check if the return value was -ECANCELED. So the completion queue is crapped up with a useless entry with a useless return value.

Also it would have been really nice if the completion queue entries contained the associated opcode to provide context for what the userdata means, especially if I use a pointer for the userdata that could point to different things depending on what the opcode was. (I could have the userdata point to a structure that has an enum and a void pointer in it but ehhh)

edit: Also would have been cool if they implemented an opcode for recvfrom so I could use it for UDP without having to use recvmsg which has all kinds of features I don't want

On the one hand I could joke about Meta and unfinished/unspecified behaviour, but on the other that looks really nice and I would have been extremely happy to have it some years back when I was last doing kernel stuff.

Adbot
ADBOT LOVES YOU

Private Speech
Mar 30, 2011

I HAVE EVEN MORE WORTHLESS BEANIE BABIES IN MY COLLECTION THAN I HAVE WORTHLESS POSTS IN THE BEANIE BABY THREAD YET I STILL HAVE THE TEMERITY TO CRITICIZE OTHERS' COLLECTIONS

IF YOU SEE ME TALKING ABOUT BEANIE BABIES, PLEASE TELL ME TO

EAT. SHIT.


Plorkyeran posted:

Yeah, for private headers - either part of an application, or headers in a library that aren't exposed - if #pragma once doesn't work you're doing something stupid and should just stop doing that. Public headers for a library should make a reasonable effort to work even if things are a bit weird, though, and header guards aren't actually very much work.

I've run into those niche cases multiple times in large corporate software (the sort of places to have tens or hundreds of people dedicated to maintaining your build pipelines), but aside from that it's not too much of an issue to switch if needed anyway. Just worth keeping in mind there are cases where it will break something that works with include guards.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply