this post was submitted on 04 Aug 2024
50 points (96.3% liked)

Tech

417 readers
1 users here now

A community for high quality news and discussion around technological advancements and changes

Things that fit:

Things that don't fit

Community Wiki

founded 7 months ago
MODERATORS
top 14 comments
sorted by: hot top controversial new old
[–] uservoid1@lemmy.world 21 points 1 month ago (4 children)

How are they going to tackle heavy use of the C preprocessor?

What about pointer arithmetic without decorating everything with "unsafe"? As the whole point is making the code safer.

[–] Diplomjodler3@lemmy.world 20 points 1 month ago

Can't have code vulnerabilities if the code doesn't run. *taps forehead*

[–] killingspark@feddit.org 7 points 1 month ago

What about pointer arithmetic without decorating everything with "unsafe"? As the whole point is making the code safer.

The point is to reduce the amount of work by doing the boring work automatically. Manually copying struct definitions, functions, etc etc would be very boring but error prone work which is kind of the worst combination.

If that's done you can start improving the codebase module by module.

[–] pelya@lemmy.world 4 points 1 month ago (1 children)

I guess it will translate the majority of the code which does not contain unsafe parts, and leave the pointer manipulation for manual rewrite.

[–] FlorianSimon@sh.itjust.works 2 points 1 month ago (1 children)

Or maybe it'll write the unsafe parts in unsafe blocks?

[–] pelya@lemmy.world 2 points 1 month ago (1 children)

Then there's no point. Converting the code to Rust as-is will also transfer all the bugs.

[–] FlorianSimon@sh.itjust.works 4 points 1 month ago

There is. It's a starting point to start converting the code to safe Rust. Some obstacles are removed.

[–] sukhmel@programming.dev 4 points 1 month ago (1 children)

~~you can just wrap a whole C code into a macro~~

yeah, preprocessor is going to blow everything, I forgot how good it is. Maybe there's a way by preprocessing and then leaving it as the code, but that wouldn't be as useful and configurable

[–] killingspark@feddit.org 1 points 1 month ago (1 children)

Rust also has powerful macros, are you sure that those can't mimic at least most uses of the preprocessor?

[–] sukhmel@programming.dev 2 points 1 month ago (1 children)

You're right, but:

  • Rust goes out of the way to make macro safer and less error-prone, which means it will not be able to cover exactly the same especially in some fringe hacky cases
  • I was commenting along the lines of automatically converting one into another, I find it will either be very difficult or outright impossible without human rewriting the macro from ground up (that is, if we know what problem it solved in the very beginning, otherwise it quickly would become guessing game)
[–] killingspark@feddit.org 1 points 1 month ago (1 children)

There is the project c2rust which is being used to transpile c projects to rust. I didn't find any mentions on restrictions in this regard but I obviously agree it's a complicated issue.

, which means it will not be able to cover exactly the same especially in some fringe hacky cases

I'm just not sure this is true. Maybe you and I just don't see that there is always an equivalent solution in rust macros even if it's going to be unconventional/unidiomatic use of rust macros?

[–] sukhmel@programming.dev 2 points 1 month ago

Maybe you and I just don't see that there is always an equivalent solution in rust macros even if it's going to be unconventional/unidiomatic use

Maybe so, but large part of where it will be impossible is reproducing bugs introduced by unsanitized macros in C /half joking

[–] onlinepersona@programming.dev -1 points 1 month ago* (last edited 1 month ago) (1 children)

Can't spell CVE without C 😉

No wonder security aware environments want to get rid of the language. It's a mess and a half (can't forget the buffer overflow).

However the suggestion of using AI kinda voids the proposal and erodes credibility.

Anti Commercial-AI license

[–] JackbyDev@programming.dev 2 points 1 month ago

Can't spell CVE without C. It's a mess and a half (can't forget the buffer overflow).

I'm saving these, folks are gonna love them lmao.