」工欲善其事,必先利其器。「—孔子《論語.錄靈公》
首頁 > 程式設計 > 使用 GNU Emacs 進行 C 語言開發

使用 GNU Emacs 進行 C 語言開發

發佈於2024-12-24
瀏覽:594

C Development with GNU Emacs

Emacs is designed with programming in mind, it supports languages like C, Python, and Lisp natively, offering advanced features such as syntax highlighting, customizable coding styles, and real-time error detection. Its built-in Lisp interpreter makes Emacs highly adaptable, allowing users to shape the editor to fit specific workflows or create entirely new functionalities.

Its rich ecosystem of extensions ensures it remains relevant across diverse fields, from academic writing to system programming, while its customizable interface enables users to optimize their environment for maximum productivity.

It continues to be a reliable choice for those who value control and versatility, proving that a tool designed decades ago can still meet the demands of today’s fast-evolving tech landscape.

Why Choose Emacs?

Emacs is more than just a text editor—it's a powerful, extensible platform for programming, writing, and customization. Unlike modern editors like VS Code or IntelliJ IDEA, Emacs thrives on flexibility and programmability. It allows users to deeply tailor their workflow, turning it into an environment suited for their exact needs. Whether you are coding in C, managing large projects, or even writing novels, Emacs can adapt to your requirements.

For new users, this might seem overwhelming, but once you understand its principles, Emacs becomes a tool that grows with you. This guide aims to help you set up a streamlined Emacs environment, from basic configurations to advanced integrations, ensuring you're productive every step of the way.

C Development with GNU Emacs

Table of Contents

  • Creating init.el
  • Ensuring the init.el Directory is Correct
  • Basic Configuration for Emacs
  • Adding the Linux Kernel Coding Style Patterns
  • Installing and Configuring the MELPA Package Manager
  • Installing the Clang LSP Server
  • Enhancing C Development with Company, Projectile, Treemacs, and Magit
  • Adding GNU Global, GTags, and Helm-Gtags
  • Using YASnippet for Code Templates
  • Configuring Semantic for Context-Aware Navigation
  • Practical Workflow Example for Development
  • Cheat Sheets
  • References for Plugins
  • Additional Learning Resources

Steps:

Creating init.el

  1. Open Emacs on your system.
  2. Use the command C-x C-f (press Ctrl and x, then Ctrl and f), which opens a file for editing.
  3. Type the file path ~/.emacs.d/init.el to create or edit your Emacs configuration file and press Enter.
  4. Add your desired configurations to the buffer. Once done, save the changes with C-x C-s (press Ctrl and x, then Ctrl and s).

Ensuring the init.el Directory is Correct

To ensure that the Emacs configuration always references the correct directory for the init.el file, add the following snippet to the top of your init.el file:

(setq user-emacs-directory "~/.emacs.d/")

This explicitly sets the user-emacs-directory variable to ~/.emacs.d/, ensuring that Emacs uses the specified path for its initialization file and related configurations. This approach avoids potential issues where Emacs might reference a different directory due to environment-specific settings.

Basic Configuration for Emacs

Here’s a simple and practical Emacs setup, explained clearly to help you understand its purpose. This configuration enhances usability, simplifies the interface, and ensures an efficient coding experience.

This line consolidates all backup files into a single directory (~/.saves). It keeps your projects clean and avoids cluttering your workspace.

(setq backup-directory-alist `(("." . "~/.saves")))

To reduce distractions, this removes unnecessary interface elements like the toolbar, scroll bar, tooltips, and menu bar. A cleaner interface helps you focus on coding without visual noise.

(tool-bar-mode -1)
(scroll-bar-mode -1)
(tooltip-mode -1)
(menu-bar-mode -1)

This setup disables the Emacs startup screen, removes the default message in the *scratch* buffer, and silences the system bell. It creates a distraction-free environment right from the start.

(setq inhibit-startup-screen t
      initial-scratch-message nil
      ring-bell-function 'ignore)

The cursor is set to a box style for better visibility, and the blinking effect is disabled. Automatic pairing of parentheses and indentation are enabled, making coding smoother and faster.

(setq cursor-type 'box
      blink-cursor-mode nil
      electric-pair-mode 1
      electric-indent-mode 1)

Line numbers are displayed globally for easier navigation, and the column number is shown in the status bar to keep track of cursor position in each line.

(global-display-line-numbers-mode t)
(column-number-mode t)

This configuration adds a clean and concise time display in the mode line, showing the day, date, and time in 24-hour format. The load average is excluded to keep the interface minimal.

(setq display-time-format "%a %b %d %R"
      display-time-interval 60
      display-time-default-load-average nil)
(display-time-mode 1)

Selections automatically replace highlighted text when typing, and clipboard integration ensures seamless copying and pasting between Emacs and other applications.

(setq select-enable-primary nil
      select-enable-clipboard t)
(delete-selection-mode 1)

All encoding is set to UTF-8, ensuring compatibility with modern text formats and avoiding encoding issues, particularly when working with international text or source code.

(set-terminal-coding-system 'utf-8)
(set-language-environment 'utf-8)
(set-keyboard-coding-system 'utf-8)
(prefer-coding-system 'utf-8)
(setq locale-coding-system 'utf-8)
(set-default-coding-systems 'utf-8)

Syntax highlighting is enabled globally with global-font-lock-mode. Long lines are wrapped naturally with visual-line-mode. Parentheses are highlighted when the cursor is near them, and recently opened files are tracked for quick access.

(global-font-lock-mode t)
(global-visual-line-mode 1)
(show-paren-mode 1)
(recentf-mode 1)

The tangotango theme provides a visually appealing color scheme. The font is set to "Consolas" with bold weight and size 15.2pt for better readability during long coding sessions.

(use-package tangotango-theme
  :ensure t
  :init (load-theme 'tangotango t))
(set-face-attribute 'default nil :family "Consolas" :height 152 :weight 'bold)

Note: Remember, we are using Emacs Lisp (Elisp), a functional programming language, to configure Emacs. This is a huge advantage, as it allows for highly flexible, programmable customization. The ability to write logic in a powerful Lisp dialect makes Emacs not just an editor, but a platform for personalized workflows.


Adding the Linux Kernel Coding Style Patterns

The configuration provided below sets up Emacs to strictly adhere to the Linux kernel coding style, emphasizing 8-character tabs, K&R brace placement, and clear readability. It includes a custom alignment function for argument lists, automatic detection of kernel-related files (e.g., files with Kbuild, Kconfig, or kernel headers), and applies the appropriate style automatically. This ensures consistency and simplifies kernel code editing in Emacs.

The linux-kernel-coding-style/setup function configures Emacs for kernel-specific settings like indent-tabs-mode, tab-width and c-basic-offset to 8, while the linux-kernel-coding-style/c-lineup-arglist-tabs-only function aligns argument lists using tabs, maintaining compliance with kernel guidelines. These hooks automatically apply the style to c-mode when editing Linux kernel files, improving productivity and adherence to coding standards.

(eval-when-compile (require 'cl))
(require 'cc)

(defun linux-kernel-coding-style/c-lineup-arglist-tabs-only (ignored)
  "Line up argument lists by tabs, not spaces"
  (let* ((anchor (c-langelem-pos c-syntactic-element))
         (column (c-langelem-2nd-pos c-syntactic-element))
         (offset (- (1  column) anchor))
         (steps (floor offset c-basic-offset)))
    (* (max steps 1)
       c-basic-offset)))

;; Add Linux kernel style
(add-hook 'c-mode-common-hook
          (lambda ()
            (c-add-style "linux-kernel"
                         '("linux" (c-offsets-alist
                                    (arglist-cont-nonempty
                                     c-lineup-gcc-asm-reg
                                     linux-kernel-coding-style/c-lineup-arglist-tabs-only))))))

(defun linux-kernel-coding-style/setup ()
  (let ((filename (buffer-file-name)))
    ;; Enable kernel mode for the appropriate files
    (when (and filename
               (or (locate-dominating-file filename "Kbuild")
                   (locate-dominating-file filename "Kconfig")
                   (save-excursion (goto-char 0)
                                   (search-forward-regexp "^#include $" nil t))))
      (setq indent-tabs-mode t)
      (setq tab-width 8)
      (setq c-basic-offset 8)
      (c-set-style "linux-kernel")
      (message "Setting up indentation for the Linux kernel"))))

(add-hook 'c-mode-hook 'linux-kernel-coding-style/setup)

(provide 'linux-kernel-coding-style)

Add this configuration to your Emacs initialization file (init.el). Emacs will now automatically detect Linux kernel files and apply the proper coding style, saving you time and ensuring compliance with the kernel's coding standards.


Installing and Configuring the MELPA Package Manager

MELPA makes it easy to install additional packages in Emacs.

Steps:

  • Add MELPA to Emacs:
  ;; Set up package repositories
  (require 'package)
  (setq package-archives
        '(("melpa" . "https://melpa.org/packages/")
          ("gnu" . "https://elpa.gnu.org/packages/")))
  (package-initialize)

  ;; Refresh package list if needed
  (unless package-archive-contents
    (package-refresh-contents))
  • Automatically install packages if they're not present:
  ;; Helper function to install packages
  (defun ensure-package-installed (&rest packages)
    "Ensure that the given PACKAGES are installed."
    (mapcar
     (lambda (package)
       (unless (package-installed-p package)
         (package-install package)))
     packages))

After making changes to your init.el file or adding new configurations, you can refresh Emacs without closing and reopening:

  1. Reload the init.el File:

    • Press M-x (Alt x), type eval-buffer, and press Enter while in your init.el buffer.
    • Alternatively, use the shortcut C-x C-e at the end of the code block to evaluate it.
  2. Manually Evaluate Code:

    • Select the code snippet you want to reload, press M-x, type eval-region, and press Enter.

This allows you to immediately apply changes to your Emacs configuration without restart


Installing the Clang LSP Server

The Language Server Protocol (LSP) provides advanced features like auto-completion and real-time error checking.

Necessary Requirements

Windows

  • LLVM/Clang:
    • Download the LLVM installer from the official website: LLVM Releases
    • During installation, make sure to add LLVM to the system PATH.

Linux

  • Debian/Ubuntu:
  sudo apt-get install clang clangd
  • Fedora:
  sudo dnf install clang clang-tools-extra

FreeBSD

  • Install clangd:
  pkg install clangd

Steps:

  • Install lsp-mode and company-mode:
  ;; Ensure that the packages are installed
  (ensure-package-installed 'lsp-mode 'company)

  ;; Enable lsp-mode for C/C  
  (add-hook 'c-mode-hook #'lsp)
  (add-hook 'c  -mode-hook #'lsp)

  ;; Enable company-mode for auto-completion
  (add-hook 'after-init-hook 'global-company-mode)
  • Configure the path to clangd if necessary:
  ;; Set the path to clangd
  (setq lsp-clients-clangd-executable "clangd")
  • Optional: Set up advanced syntax highlighting with lsp-ui:
  ;; Install lsp-ui
  (ensure-package-installed 'lsp-ui)

  ;; Enable lsp-ui
  (add-hook 'lsp-mode-hook 'lsp-ui-mode)

What is LSP and Why Use It?

The Language Server Protocol (LSP) bridges the gap between editors and programming languages, providing features like auto-completion, error checking, and code navigation. This is particularly useful for C/C development, where managing headers, debugging, and navigating large codebases can be challenging.

By setting up LSP in Emacs, you gain the ability to:

  • View real-time syntax errors as you type.
  • Jump to function or variable definitions instantly.
  • Access intelligent suggestions for completing code.

This makes Emacs competitive with modern IDEs while retaining its lightweight and customizable nature.

Company, Projectile, Treemacs, and Magit

Enhancing your Emacs setup for C development involves integrating Company, Projectile, Treemacs, and Magit. Company provides auto-completion for C programming, enabling real-time suggestions for functions, variables, and keywords, making coding faster and more efficient. By configuring it to use company-clang, you ensure robust support tailored to C development.

Projectile streamlines project management by allowing quick navigation, file discovery, and project compilation. It pairs seamlessly with Treemacs, which provides a visual, tree-based representation of your project structure, helping you locate and manage files intuitively. Finally, Magit is an advanced interface for Git, providing powerful tools for version control directly within Emacs.

With shortcuts like C-x g, you can perform operations such as commits, branching, and merging interactively, enhancing your workflow and productivity. Here’s the complete configuration to set up these tools in your Emacs environment:

;; Ensure required packages are installed
(ensure-package-installed 'company 'projectile 'treemacs 'treemacs-projectile 'magit)

;; Company Setup for Auto-Completion
(add-hook 'after-init-hook 'global-company-mode) ;; Enable globally
(add-hook 'c-mode-hook
          (lambda ()
            (setq-local company-backends '(company-clang company-capf company-files)))) ;; Configure for C
(setq company-minimum-prefix-length 1
      company-idle-delay 0.2) ;; Show suggestions after 0.2 seconds

;; Projectile Setup for Project Management
(projectile-mode  1) ;; Enable globally
(setq projectile-project-search-path '("~/projects/")) ;; Set your project directory
(setq projectile-completion-system 'default) ;; Use default completion system
(global-set-key (kbd "C-c p") 'projectile-command-map) ;; Set a keybinding for Projectile commands

;; Treemacs Setup for Tree-Based File Navigation
(global-set-key (kbd "M-0") 'treemacs) ;; Toggle Treemacs
(global-set-key (kbd "C-x t t") 'treemacs) ;; Alternate keybinding
(with-eval-after-load 'treemacs
  (treemacs-projectile)) ;; Integrate with Projectile
(setq treemacs-width 30 ;; Set tree width
      treemacs-is-never-other-window t) ;; Prevent Treemacs from taking focus

;; Magit Setup for Git Version Control
(global-set-key (kbd "C-x g") 'magit-status) ;; Open Magit status interface

Practical Workflow Example

Let’s see how you can combine these tools in a real-world scenario:

  1. Open a Project:
    • Use C-c p f to quickly find a file within your project directory using Projectile.
  2. Navigate Files Visually:
    • Open Treemacs with M-0, and use the arrow keys to browse your project structure. Double-click a file to open it.
  3. Git Workflow with Magit:
    • Stage changes: Open Magit with C-x g, press s to stage files.
    • Commit: Press c c to commit changes with a message.
    • Push: Use P to push changes to your remote repository.
  4. Code Completion:
    • While editing a .c file, type a function name partially and use company-mode suggestions by pressing TAB.

Enhancements to Add to the Article

  1. GNU Global and GTags Configuration:
    • Add instructions for setting up GNU Global and GTags for code navigation:
   ;; Install and configure ggtags
   (require 'ggtags)
   (add-hook 'c-mode-common-hook
             (lambda ()
               (when (derived-mode-p 'c-mode 'c  -mode 'java-mode 'asm-mode)
                 (ggtags-mode 1))))

   ;; Keybindings for ggtags
   (define-key ggtags-mode-map (kbd "C-c g s") 'ggtags-find-other-symbol)
   (define-key ggtags-mode-map (kbd "C-c g h") 'ggtags-view-tag-history)
   (define-key ggtags-mode-map (kbd "C-c g r") 'ggtags-find-reference)
   (define-key ggtags-mode-map (kbd "C-c g f") 'ggtags-find-file)
   (define-key ggtags-mode-map (kbd "C-c g u") 'ggtags-update-tags)
  1. Helm-Gtags Integration:
    • Include configuration for helm-gtags to enhance project navigation:
   (setq
    helm-gtags-ignore-case t
    helm-gtags-auto-update t
    helm-gtags-use-input-at-cursor t
    helm-gtags-pulse-at-cursor t
    helm-gtags-prefix-key "\C-cg"
    helm-gtags-suggested-key-mapping t)

   (require 'helm-gtags)
   (add-hook 'c-mode-hook 'helm-gtags-mode)
   (add-hook 'c  -mode-hook 'helm-gtags-mode)
  1. Yasnippet Templates:
    • Include YASnippet for code templates:
   (require 'yasnippet)
   (yas-global-mode 1)
   ;; Example snippet for C-mode
   (add-to-list 'yas-snippet-dirs "~/.emacs.d/snippets")
   (yas-reload-all)
   (add-hook 'c-mode-hook #'yas-minor-mode)
  1. Semantic Configuration:
    • Add Semantic for context-aware code completion and parsing:
   (require 'cc-mode)
   (require 'semantic)
   (global-semanticdb-minor-mode 1)
   (global-semantic-idle-scheduler-mode 1)
   (semantic-mode 1)

   ;; Add include paths for Semantic
   (semantic-add-system-include "/usr/include/boost" 'c  -mode)
   (semantic-add-system-include "~/linux/include")
  1. Additional Code Navigation Features:
    • Mention semantic-symref for reference gathering:
   (add-hook 'c-mode-common-hook
             (lambda ()
               (local-set-key (kbd "C-c , g") 'semantic-symref)))

These additions enhance the existing content by providing support for advanced navigation, project management, and automation tools in Emacs, aligning the article with best practices for modern C/C development.


Cheat Sheets

C Development with GNU Emacs

C Development with GNU Emacs


References for Plugins

  • lsp-mode: Language Server Protocol support for auto-completion and error checking. GitHub
  • company-mode: Context-aware autocompletion. GitHub
  • lsp-ui: UI enhancements for lsp-mode. GitHub
  • projectile: Project navigation and management. GitHub
  • treemacs: Tree-based file explorer. GitHub
  • magit: Git interface for Emacs. GitHub
  • ggtags: GNU Global integration for code navigation. GitHub
  • helm-gtags: Navigation with GNU Global and Helm. GitHub
  • yasnippet: Snippet management for reusable code. GitHub
  • semantic: Advanced code parsing and navigation. GNU CEDET

Additional Learning Resources

  • Emacs for Beginners: A beginner-friendly guide to setting up and using Emacs. Link
  • Introduction to Emacs Lisp: Learn how to customize Emacs using Lisp. Link
  • Linux Kernel Coding Style: Official documentation on kernel coding standards. Link
  • Setting Up Emacs for C Development: A practical guide to configure Emacs for C/C programming. Link
版本聲明 本文轉載於:https://dev.to/scovl/c-development-with-gnu-emacs-j38如有侵犯,請聯絡[email protected]刪除
最新教學 更多>
  • 在 Go 中使用 WebSocket 進行即時通信
    在 Go 中使用 WebSocket 進行即時通信
    构建需要实时更新的应用程序(例如聊天应用程序、实时通知或协作工具)需要一种比传统 HTTP 更快、更具交互性的通信方法。这就是 WebSockets 发挥作用的地方!今天,我们将探讨如何在 Go 中使用 WebSocket,以便您可以向应用程序添加实时功能。 在这篇文章中,我们将介绍: WebSoc...
    程式設計 發佈於2024-12-25
  • 大批
    大批
    方法是可以在物件上呼叫的 fns 數組是對象,因此它們在 JS 中也有方法。 slice(begin):將陣列的一部分提取到新數組中,而不改變原始數組。 let arr = ['a','b','c','d','e']; // Usecase: Extract till index ...
    程式設計 發佈於2024-12-25
  • 如何在 PHP 中組合兩個關聯數組,同時保留唯一 ID 並處理重複名稱?
    如何在 PHP 中組合兩個關聯數組,同時保留唯一 ID 並處理重複名稱?
    在 PHP 中組合關聯數組在 PHP 中,將兩個關聯數組組合成一個數組是常見任務。考慮以下請求:問題描述:提供的代碼定義了兩個關聯數組,$array1 和 $array2。目標是建立一個新陣列 $array3,它合併兩個陣列中的所有鍵值對。 此外,提供的陣列具有唯一的 ID,而名稱可能重疊。要求是建...
    程式設計 發佈於2024-12-25
  • Bootstrap 4 Beta 中的列偏移發生了什麼事?
    Bootstrap 4 Beta 中的列偏移發生了什麼事?
    Bootstrap 4 Beta:列偏移的刪除和恢復Bootstrap 4 在其Beta 1 版本中引入了重大更改柱子偏移了。然而,隨著 Beta 2 的後續發布,這些變化已經逆轉。 從 offset-md-* 到 ml-auto在 Bootstrap 4 Beta 1 中, offset-md-*...
    程式設計 發佈於2024-12-25
  • 插入資料時如何修復「常規錯誤:2006 MySQL 伺服器已消失」?
    插入資料時如何修復「常規錯誤:2006 MySQL 伺服器已消失」?
    插入記錄時如何解決「一般錯誤:2006 MySQL 伺服器已消失」介紹:將資料插入MySQL 資料庫有時會導致錯誤「一般錯誤:2006 MySQL 伺服器已消失」。當與伺服器的連線遺失時會出現此錯誤,通常是由於 MySQL 配置中的兩個變數之一所致。 解決方案:解決此錯誤的關鍵是調整wait_tim...
    程式設計 發佈於2024-12-25
  • HTML 格式標籤
    HTML 格式標籤
    HTML 格式化元素 **HTML Formatting is a process of formatting text for better look and feel. HTML provides us ability to format text without us...
    程式設計 發佈於2024-12-24
  • 儘管程式碼有效,為什麼 POST 請求無法擷取 PHP 中的輸入?
    儘管程式碼有效,為什麼 POST 請求無法擷取 PHP 中的輸入?
    解決PHP 中的POST 請求故障在提供的程式碼片段中:action=''而非:action="<?php echo $_SERVER['PHP_SELF'];?>";?>"檢查$_POST陣列:表單提交後使用 var_dump 檢查 $_POST 陣列的內...
    程式設計 發佈於2024-12-24
  • Java中如何使用Selenium WebDriver高效率上傳檔案?
    Java中如何使用Selenium WebDriver高效率上傳檔案?
    在Java 中使用Selenium WebDriver 上傳文件:詳細指南將文件上傳到Web 應用程式是軟體測試期間的一項常見任務。 Selenium WebDriver 是一種流行的自動化框架,它提供了一種使用 Java 程式碼上傳檔案的簡單方法。然而,重要的是要明白,在 Selenium 中上傳...
    程式設計 發佈於2024-12-24
  • 使用 GNU Emacs 進行 C 語言開發
    使用 GNU Emacs 進行 C 語言開發
    Emacs is designed with programming in mind, it supports languages like C, Python, and Lisp natively, offering advanced features such as syntax highli...
    程式設計 發佈於2024-12-24
  • 如何在 PHP 中列印單引號內的變數?
    如何在 PHP 中列印單引號內的變數?
    無法直接回顯帶有單引號的變數需要在單引號字串中列印變數?直接這樣做是不可能的。 如何在單引號內列印變數:方法1:使用串聯追加 為此,請使用點運算子將變數連接到字串上:echo 'I love my ' . $variable . '.';此方法將變數追加到字串中。 方法 2:使用雙引號或者,在字串並...
    程式設計 發佈於2024-12-24
  • std::vector 與普通數組:何時效能真正重要?
    std::vector 與普通數組:何時效能真正重要?
    std::vector 與普通數組:性能評估雖然人們普遍認為std::vector 的操作與數組類似,但最近的測試對這一概念提出了挑戰。在本文中,我們將研究 std::vector 和普通數組之間的效能差異,並闡明根本原因。 為了進行測試,實施了一個基準測試,其中涉及重複建立和修改大型陣列像素物件。...
    程式設計 發佈於2024-12-24
  • 為什麼雙精確度的小數位數比宣傳的 15 位多?
    為什麼雙精確度的小數位數比宣傳的 15 位多?
    雙精度和小數位精度在電腦程式設計中,雙精度資料型態通常被假定為具有 15 位小數的近似精度。但是,某些數字表示形式(例如 1.0/7.0)在變數內部表示時似乎具有更高的精確度。本文將探討為什麼會發生這種情況,以及為什麼精確度通常被描述為小數點後 15 位左右。 內部表示IEEE 雙精度數有 53 個...
    程式設計 發佈於2024-12-24
  • 箭頭函數中的隱式回傳與明確傳回:何時需要大括號?
    箭頭函數中的隱式回傳與明確傳回:何時需要大括號?
    箭頭函數中的花括號:隱式與明確返回箭頭函數可以用兩種方式編寫:帶或不帶花括號。當大括號不存在時,函數體被認為是“簡潔體”,並且隱式傳回其中的最後一個表達式。 帶有簡潔體的隱式回傳In不帶大括號的範例:state.map(one => oneTodo(one, action))The函數立即傳回...
    程式設計 發佈於2024-12-24
  • 為什麼使用「transform:scale()」後我的文字在 Chrome 中變得模糊?
    為什麼使用「transform:scale()」後我的文字在 Chrome 中變得模糊?
    變換後Chrome 中的文字模糊:scale()在最近的Chrome 更新中,出現了一個特殊問題,即使用CSS 轉換呈現的文字:scale() 屬性顯得模糊。使用以下特定程式碼時已觀察到此問題:@-webkit-keyframes bounceIn { 0% { opacity: 0; ...
    程式設計 發佈於2024-12-24
  • 如何在 GoLang 中實作 MDC 日誌記錄?
    如何在 GoLang 中實作 MDC 日誌記錄?
    GoLang 中的 MDC LoggingJava 的 MDC Logging 依賴線程本地存儲,這在 GoLang 中不可用。然而,透過堆疊中的線程化 Context 可以實現類似的功能。 Java MDC 依賴線程本地存儲,這是 Go 所不具備的。最接近的是透過堆疊線程化 Context,這正在...
    程式設計 發佈於2024-12-23

免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。

Copyright© 2022 湘ICP备2022001581号-3