- عنوان کتاب: c3 programming tutorial
- نویسنده: Suzanna Linn, Matthew J. Lebo, Clayton Webb
- حوزه: برنامهنویسی سیستمی
- سال انتشار: 2026
- تعداد صفحه: 385
- زبان اصلی: انگلیسی
- نوع فایل: pdf
- حجم فایل: 3.45 مگابایت
اسناد رسمی C3، C3 را به عنوان “تکاملی از C” تعریف میکند. این یک زبان برنامهنویسی سیستمهای مینیمالیستی است. برای درک این توصیف، ابتدا به مشکلاتی که C3 سعی در حل آنها دارد فکر کنید. C بیش از 50 سال است که وجود دارد و هنوز هم یک زبان اصلی در زمینههای سطح پایین مانند سیستمهای عامل، سیستمهای تعبیهشده و موتورهای بازی است. دلیل آن ساده است: C به اندازه کافی به سختافزار نزدیک است، فایلهای باینری کوچک و سریع تولید میکند و میتواند تقریباً به طور یکپارچه با C ABI در تقریباً هر پلتفرمی تعامل داشته باشد. اما C همچنین نقاط ضعف شناختهشدهای دارد: مدیریت دستی حافظه مستعد خطا است، فقدان فضاهای نام باعث تداخل نمادها در پروژههای بزرگ میشود، مدیریت خطا اغلب به قرارداد شکننده مقادیر بازگشتی به علاوه خطای سراسری متکی است و این زبان تقریباً هیچ پشتیبانی در سطح زبان برای ژنریکها یا ماکروها ندارد. طراحی C3 “اختراع یک زبان کاملاً جدید برای جایگزینی C” نیست. در عوض، اسکلت نحوی و مدل زمان اجرا C را حفظ میکند، در حالی که فقط در مواردی که C واقعاً مانع بهرهوری و ایمنی میشود، ویژگیهایی را اضافه میکند. به طور خاص، C3 موارد زیر را به C اضافه میکند: -سیستم ماژول: C3 از ماژول برای تقسیم فضاهای نام استفاده میکند و روشی را که C به صورت دستی ماژولاریتی را شبیهسازی میکند با فایلهای هدر و نامهای پیشوندی مانند mylib_do_thing جایگزین میکند. -مکانیسم اختیاری: C3 عبارت “این تابع ممکن است شکست بخورد” را در سیستم نوع با Type? نشان میدهد و آن را با فرمهایی مانند postfix ~، !، !!، ??، if (try …) و if (catch …) برای مدیریت خطای بدون هزینه ترکیب میکند. این جایگزین قرارداد شکننده C مبنی بر “کد خطا را برگردان، و به یاد داشته باش که آن را بررسی کنی” میشود. -برشها و تکرار ایمن: انواع foreach و slice هنگام تکرار روی آرایهها، اطلاعات مرزها را حمل میکنند و خطاهای خارج از محدوده ناشی از حساب اشارهگر دستنویس را کاهش میدهند. -ماژولهای عمومی، ماکروها و بازتاب زمان کامپایل: کد کانتینر میتواند یک بار نوشته شود و برای انواع دلخواه دوباره استفاده شود، به جای اینکه مانند C با ماکروها یا void* کدگذاری شود. -دستور defer: کد پاکسازی هنگام خروج از یک محدوده به طور خودکار اجرا میشود و جایگزین پاکسازی دستی مکرر قبل از هر بازگشت میشود. -سازگاری کامل با ABI زبان C: توابع کامپایل شده از زبان C3 را میتوان مستقیماً از کد C فراخوانی کرد و زبان C3 میتواند مستقیماً کتابخانههای موجود C را فراخوانی کند و هزینههای مهاجرت و قابلیت همکاری را پایین نگه دارد.
The official C3 documentation defines C3 as “an evolution of C.” It is a minimalist systems programming language. To understand that description, it helps to first think about the problems C3 is trying to solve. C has existed for more than 50 years and is still a primary language in low-level fields such as operating systems, embedded systems, and game engines. The reason is simple: C is close enough to the hardware, produces small and fast binaries, and can interoperate almost seamlessly with the C ABI on nearly any platform. But C also has well-known pain points: manual memory management is error-prone, the lack of namespaces causes symbol conflicts in large projects, error handling often relies on the fragile convention of return values plus global errno, and the language has almost no language-level support for generics or macros. C3’s design is not “invent a completely new language to replace C.” Instead, it preserves C’s syntactic skeleton and runtime model, while adding features only where C genuinely gets in the way of productivity and safety. More specifically, C3 adds the following on top of C: -Module system: C3 uses module to divide namespaces, replacing the way C manually simulates modularity with header files and prefixed names such as mylib_do_thing. -Optional mechanism: C3 represents “this function may fail” in the type system with Type?, and combines it with forms such as postfix ~, !, !!, ??, if (try …), and if (catch …) for zero-cost error handling. This replaces the fragile C convention of “return an error code, and remember to check it.” -Slices and safe iteration: foreach and slice types carry bounds information when iterating over arrays, reducing out-of-bounds errors caused by handwritten pointer arithmetic. -Generic modules, macros, and compile-time reflection: container code can be written once and reused for arbitrary types, instead of being hardcoded with macros or void* as in C. -defer statement: cleanup code runs automatically when leaving a scope, replacing repeated manual cleanup before every return. -Full C ABI compatibility: functions compiled from C3 can be called directly from C code, and C3 can directly call existing C libraries, keeping migration and interoperability costs low.
این کتاب را میتوانید از لینک زیر بصورت رایگان دانلود کنید:
Download: c3 programming tutorial





نظرات کاربران