{
  "id": 12657631,
  "title": "C for Rust Programmers",
  "url": "https://urgent.news/2026/10/07/c-for-rust-programmers",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-10-07T14:30:05.000Z",
  "source": {
    "name": "Lobsters",
    "slug": "lobsters",
    "url": "https://bd103.dev/blog/2026-10-07-c-for-rust-programmers/"
  },
  "original_language": "en",
  "account": "For those who have learned Rust, diving into the world of C can be quite a challenge. This article aims to provide insights and considerations for programmers making the transition from Rust to C.\n\nIn the early days of systems programming, Rust was not the first language many learned. C and C++ were more commonly studied before arriving at Rust. Consequently, there are numerous articles on learning Rust for those familiar with C, but few resources are dedicated to C for those skilled in Rust.\n\nHaving recently delved into C and C++, the author highlights various peculiarities of the language, offering a collection of noteworthy details from their self-taught journey. Please note that this post does not serve as a comprehensive C tutorial but rather provides a checklist of factors to consider when working with the language.\n\nTo start, the original version of C did not include a primitive type for booleans. Instead, programs utilized integers 0 and 1. This changed in C99 with the introduction of booleans in the optional stdbool.h header. True and false are not literals or keywords in C; they are defined as 1 and 0, respectively. In C23, booleans became native language primitives, but for earlier versions, including stdbool.h is necessary.\n\nThe memory usage for strings in Rust's &str type differs significantly from C. An &str in Rust occupies 16 bytes, with 8 bytes for the memory address and 8 bytes for the string length. This is due to str being a dynamically sized type, using pointer metadata to track length. While this makes retrieving the string length efficient, it requires more memory per reference. C, on the other hand, terminates strings with a null byte (\\0) to avoid storing size separately. This approach results in:\n\n1. The need to allocate extra space for the null terminator.\n2. The necessity to insert it at the end of strings manually.\n\nIn practice, this leads to extra attention to detail when handling strings. The following C program demonstrates reversing a string, accounting for the null terminator:\n\n```c\n#include <stdio.h>\n\nvoid reverse_string(char* str) {\nint n = strlen(str);\nfor (int i = 0; i < n / 2; i++) {\nchar temp = str[i];\nstr[i] = str[n - i - 1];\nstr[n - i - 1] = temp;\n}\n}\n\nint main() {\nchar str[] = \"Hello\";\nreverse_string(str);\nprintf(\"%s\\n\", str);\nreturn 0;\n}\n```\n\nNote the special handling on lines 5 and 12 to account for the null terminator. In contrast, a Rust implementation of string reversal doesn't require such measures.\n\nC's integer types lack a guaranteed number of bits. The width varies depending on the target platform. For instance, long is 64 bits on Unix and 32 bits on Windows. This inconsistency can be jarring, especially for cross-platform compatibility. The author recommends using fixed-width integers from stdint.h for such cases.",
  "summary": null,
  "key_points": [],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}