• 0 Posts
  • 74 Comments
Joined 1 year ago
cake
Cake day: June 15th, 2023

help-circle
  • I think you dont fully understand how c compilers ( gcc specifically ) work when using multi file projects

    They don’t. C compilers compile single files produced by the c preprocessor (resolving all #includes), they have no concept of multi-file projects. That’s a thing for the build system, such as make, and it needs dependency information from the preprocessor to do its job (cpp -M), and once it has that it has to act correctly on them which is often completely broken because people don’t understand make. Like using it recursively, bad idea. In the wild, a random C project at work you’ll come across needs a full rebuild to build cleanly. Things have gotten better with things like cmake getting more popular but the whole thing is still brittle. GNU autohell certainly makes nothing better, ever.

    Also, anything using IL will always have an abi,

    Everything will always have an ABI because ABI is just API in the target language, whatever that may be. If your program is compiled and can run it uses an ABI.

    Wasm is wasm, and you only need an exposed interface

    The core wasm abi is less capable than the C abi: You get scalar values and pointers, that’s it. No structs, no nothing, memory layout is completely unspecified. The component model allows compilers to say “so I’m laying out strings like this and structs like that” giving linkers a chance to say “yeah I can generate glue code between you two”.

    Again, i like the idea of rust, but it has a long way to go to be viable atm.

    C isn’t even close to being viable according to your standards people just have gotten used to the jank.

    And it has many pitfalls to avoid so it doesnt become the hot mess that is any framework based on node.js

    Rust doesn’t have portable dylibs precisely because it isn’t a hot mess. Because it’s actual work to do it properly. Unlike everyone else. Meanwhile It speaks the local C ABI fluently (they differ by architecture and operating system, btw), which isn’t a thing that can be said about many languages that aren’t C.


    Differently put: What, precisely, do you want to do? Have you any actual use-case for your doubts, or are they spooks?


  • It’s a lacking point yes but unless you want to use a closed-source library it’s also a non-issue, which is why it has never been given priority. It’s not like language semantics would prevent portable dylibs it’s that there’s more important fronts to improve Rust on. A proper solution would take quite some engineering effort, and do note that C doesn’t have a proper solution either it just lets you link stuff up willy-nilly and then crash. Rust is actually in a better position to implement a proper solution than C is.

    The “big project” thing is a red herring given that rust compiles incrementally. I know it is technically possible to not rebuild everything from scratch in C but the code has to specifically written to not break assumptions your build system makes while rust is happily re-using the compilation results for one function in a file while discarding those of another because actual dependencies are actually tracked. Out of the box.

    Speaking of large Rust projects and proper type-safe linking: The WebAssembly folks are hashing out their Component Model which isn’t really limited to compiling to wasm, in principle: Big picture it’s a way to programmatically specify ABIs and even derive ABI translation code. That might be a good option as a rust-specific solution would be, well, rust-specific and when you engineer something that can support multiple versions of a language you can just as well engineer a bit more and have something cross-language.



  • The Rustinomicon has a chapter on it. The basics are quite simple: Declare non-opaque types to use layout matching the C ABI, export/import functions, some wibbles around name mangling. Option<T> vs. null pointers. Where things get a bit more involved is unwinding, but then you’re at the end of it, nothing should be shocking to anyone having written C.

    As to how Rusty it is… not very. I mean Rust has first-class FFI support, but the way FFI stuff is written is necessarily unidiomatic because you’re basically writing C in Rust syntax and you won’t get out of declaring your own functions `unsafe’ before you read the rest of the Rustinomicon to understand what properties you need to ensure because the nice and shiny parts of Rust assume them.



  • Data after dst+n is unchanged.

    Sure but that means the part before that is garbage because you have a null terminated string without terminator.

    Or at least that’s how I see it. If your intention isn’t to start and end with a null-terminated string you should be using memcpy. Let us not talk about situations where CHAR_BIT != 8 that’s not POSIX anyway.

    Even better, just avoid doing string manipulation in C.



  • barsoap@lemm.eetoProgrammer Humor@programming.devA Guessing Game
    link
    fedilink
    arrow-up
    5
    arrow-down
    3
    ·
    edit-2
    2 months ago

    How on earth should a newcomer know that the letter “n” in that word stands for number without having to google it?

    By looking at the difference between strcpy and strncpy. Preferably, though, you should simply learn C before writing C.

    The gist of is is that strcpy takes a null-terminated string and copies it somewhere, while strncpy takes a zero-terminated string and copies it somewhere but will not write more than n bytes. strncpy literally has exactly one more parameter than strcpy, that being n, hence the name. If n is smaller than the string length (as in: distance to first null byte) then you’re bound to have garbage in your destination, and to check for that you have to dereference the pointer strncpy returns and check if it’s actually null. Yay C error handling.

    In retrospect null-terminated strings were a mistake, but so were many other things, at some point you just have to accept that there’s hysterical raisins everywhere.


  • That’s just Algol instead of B. Most languages use the one or the other, then there’s sexpr-based languages (lisp, scheme), lua (technically Algol but not needing semicolons while also not needing newlines so it’s definitely special), and layout syntax (Haskell, or, if you want a bad implementation, python).


  • It’s not just old Haskell code that’s how you write Haskell if you want explicit braces. Well, mostly generate, but it’s still the idiomatic formatting (and when you generate you always generate braces because it’s easy to get layout subtly wrong when generating).

    Haskell also does the whole

    data Foo = Bar
             | Baz
             | Quux
    
    foo = [ Bar
          , Baz
          , Quux
          ]
    

    thing, makes sense to apply it to braces especially as they’re seen only very rarely. Single-line, yes, but not multi-line.




  • Giving you, if you were lucky, VESA graphics and maybe a mouse pointer because XFree86 somehow insisted on being told whether you have a PS/2 or USB mouse. 3d acceleration only with nvidia and that required manual installation because nvidia never provided anything but blobs. IIRC ATI drivers were simply non-existent (didn’t have an ATI card back then), that only changed when AMD bought them. Whippensnappers won’t believe it but once upon the time, nvidia was actually the company to go with when running linux. And Epic didn’t hate Linux yet, UT2004 came with linux binaries on the dvd.


  • 32 is ASCII space, the highest number you need is 114 for r (or 122 for z if you want to be generic), that’s a range of 82 or 90 values.

    The target string has 13 characters, a long long has 8 bytes or 16 nibbles – 13 fits into 16 so nibbles (the (x >>= 4) & 15) it is. Also the initial x happens to have 13 nibbles in it so that makes sense. But a nibble only has 16 values, not 82, so you need some kind of compression and that’s the rest of the math, no idea how it was derived.

    If I were to write that thing I’d throw PAQ at it it can probably spit out an arithmetic coding that works, and look even more arcane as you wouldn’t have the obvious nibble steps. Or, wait, throw NEAT at it: Train it to, given a specific initial seed, produce a second seed and a character, score by edit distance. The problem space is small enough for the approach to be feasible even though it’s actually a terrible use of the technique, but using evolution will produce something that’s utterly, utterly inscrutable.


  • Blender changed it to just start typing one or two minor versions ago. There’s certainly stuff I have no idea how to find in the menus because F3 is way more convenient than remembering things (just be aware that you still need to be in the right mode for stuff to show up).



  • One of the issues I have with C++ is the standard library source seems to be completely incomprehensible.

    AAAAAAhhh I once read a Stroustrup quote essentially going “if you understand vectors you understand C++”, thought about that for a second, coming to the conclusion “surely he didn’t mean using them, but implementing them”, then had a quick google, people said llvm’s libc++ was clean, had a look, and noped out of that abomination instantly. For comparison, Rust’s vectors. About the same LOC, yes, but the Rust is like 80% docs and comments.


  • Half the reason why I bought an RTX GPU was for the video enhancement features like SDR to HDR conversion and AI upscaling

    Neither of those things have anything to do with raytracing. Well the tensor cores used for denoising in RT workloads are suitable for all kinds of AI workloads and thus also upscaling, but really it hasn’t got to do anything with raytracing. Or AI in particular any GPU can do convolutions.

    I don’t own an nvidia card and honestly few linux users do because their driver support sucks, I’d say if nvidia advertised those features and their linux drivers don’t have them your complaints should be directed at nvidia. They won’t care.

    Meanwhile, mpv does inverse tone mapping natively. They don’t integrate AI upscaling but there’s various projects providing glsl shaders which mpv can use, here’s the configs for Anime4K. There’s also frame interpolation around somewhere but I haven’t used it in ages because variable refresh rate is the best solution to odd frame rates.

    Development of X halted, the few patches that are still landing concern xwayland, don’t expect anything to happen there. KDE 6.0 ships with experimental HDR support on wayland, you might not need to wait five years go give a live USB stick a spin. Arch wiki has some pointers (not that I’d be recommending arch but I am recommending their wiki).


  • Hmm. Actually you prompted me to dig a bit deeper: tar goes all the back to Version 7 UNIX, 1979, but the command line syntax is shared with tap, included in Version 1, man page dated to 1971-11-03. Development of C started 1972. Might’ve been written in B, you’d have to unearth a source archive I bet it’s around somewhere. But anyway if you look through the other Version 1 commands a lot of them don’t take hyphen commands, ls does, e.g. rm doesn’t on account of only taking file names as arguments.

    dd is actually younger, Version 5, 1974, the syntax apparantly comes from IBM’s JCL.

    Admittedly, that’s all before my time.

    Both BSD and GNU tar take hyphens, I don’t really have any experience with anything else but a short stint with Solaris in the early 2000s (very emphatically before Sun got gobbled up by Oracle) and I don’t remember hyphens tripping me up. Much unlike killall. And I’m apparently not alone in that.