Skills Plugins MCP Prompt Model 博客 我的中心

polyglot-rust-c

Guidance for creating polyglot source files that compile and run correctly as both Rust and C/C++ programs. This skill should be used when asked to create code that is valid in multiple programming languages simultaneously, particularly Rust and C/C++ polyglots.

DeepseekModel Curated skill Quality Excellent · 78 v1.0.0

Get

https://deepseekmodel.com/api/download.php?id=lazyfroglol-harness-engineering-skills-polyglot-rust-c-skill-md&format=skill
Download .skill Standard format with system_prompt and model_config, ready for any agent framework
The actual content of the system_prompt field in the .skill file.
name polyglot-rust-c description Guidance for creating polyglot source files that compile and run correctly as both Rust and C/C++ programs. This skill should be used when asked to create code that is valid in multiple programming languages simultaneously, particularly Rust and C/C++ polyglots. Polyglot Rust-C Overview This skill provides guidance for creating polyglot source files—single files that compile and execute correctly as programs in multiple languages. The focus is on Rust and C/C++ polyglots, which leverage comment syntax differences and preprocessor directives to hide language-specific code from each compiler. Critical Approach: Iterative Implementation Over Analysis The most important principle for polyglot tasks is to implement and test iteratively rather than analyze extensively. Polyglot construction is inherently experimental—theoretical reasoning about syntax interactions often fails to predict actual compiler behavior. Anti-Pattern to Avoid Spending excessive time analyzing potential approaches without writing code leads to: Circular reasoning about syntax possibilities Repeated exploration of the same ideas without progress Analysis paralysis preventing any solution Required Approach Time-box exploration : Limit initial analysis to understanding the basic polyglot mechanisms, then commit to an approach Write code immediately : Create the directory structure and write an initial attempt within the first few minutes Compile with both compilers : Test with actual compilers to get real error messages Iterate based on errors : Use compiler feedback to refine the approach Track attempts : Maintain awareness of what has been tried and why it failed Polyglot Mechanisms Comment Syntax Differences The key to Rust/C++ polyglots is exploiting how each language handles comments: Syntax Rust Interpretation C/C++ Interpretation // Line comment Line comment /* */ Block comment Block comment /*/ Start of block comment (needs closing) End then start of comment //*/ Line comment End of block comment Preprocessor Directives C/C++ preprocessor directives are treated as comments or ignored by Rust: #if 0 / #endif blocks are skipped by C preprocessor Rust sees # as an attribute marker or ignores it in certain contexts Common Polyglot Patterns Pattern 1: Comment Toggle //* Rust code here C++ code here // */ Pattern 2: Preprocessor Hide #if 0 Rust-only code #endif C++ code Pattern 3: Backslash Line Continuation //\ This line is part of the comment in C++ but visible in Rust Implementation Workflow Step 1: Set Up Environment Create the required directory structure and files immediately: mkdir -p /path/to/polyglot touch /path/to/polyglot/main.rs # or appropriate filename Step 2: Write Minimal Skeleton Start with the simplest possible structure that demonstrates the polyglot mechanism: // Minimal test - does this compile in both? fn main() {} // Rust int main() { return 0; } // C++ Step 3: Compile and Test Run both compilers and collect error messages: # For Rust rustc main.rs -o rust_output # For C++ g++ main.rs -o cpp_output # or use appropriate extension handling Step 4: Iterate on Errors Address one compiler's errors at a time: Fix Rust compilation errors first (often stricter) Verify C++ still compiles Repeat until both compile Step 5: Add Actual Logic Once the skeleton works, add the required functionality incrementally: Add one function at a time Test after each addition Handle input/output as required Verification Strategy Compilation Verification Both compilers must succeed without errors: rustc main.rs -o rust_binary && echo "Rust: OK" g++ main.rs -x c++ -o cpp_binary && echo "C++: OK" Output Verification Both executables must produce identical output for the same input: echo "10" | ./rust_binary > rust_output.txt echo "10" | ./cpp_binary > cpp_output.txt diff rust_output.txt cpp_output.txt && echo "Output matches" Edge Case Testing Test boundary conditions: Zero and negative inputs (if applicable) Large values (integer overflow considerations) Invalid input handling Common Pitfalls 1. Overthinking Without Testing Problem : Extensive theoretical analysis without writing code Solution : Commit to an approach within 2-3 minutes and test it 2. Forgetting to Use Tools Problem : Reasoning about syntax without actually compiling Solution : Always create files and run compilers to verify hypotheses 3. Not Tracking Attempts Problem : Trying the same approach multiple times without realizing it Solution : Document what has been tried and the specific failure mode 4. Ignoring Compiler Error Messages Problem : Continuing to reason abstractly when compiler output provides concrete guidance Solution : Read error messages carefully—they indicate exactly what needs fixing 5. Overcomplicating the Structure Problem : Building elaborate comment nesting when simpler patterns exist Solution : Start with established polyglot patterns before inventing new ones 6. Function Definition Differences Problem : Forgetting that Rust uses fn while C++ uses return types Solution : Use comment blocks to hide each language's function definitions from the other Algorithm Considerations When implementing algorithms in polyglots: Fibonacci Example Be aware of definition variations: Common: f(0)=0, f(1)=1 Alternative: f(0)=1, f(1)=1 Verify the expected definition before implementing. Integer Overflow Rust may panic on overflow in debug mode C++ has undefined behavior for signed overflow Consider using appropriate types and bounds checking Resources Reference material for polyglot construction is available in the references/ directory. references/ Contains documentation on polyglot patterns and language-specific syntax details that inform the construction process.
Keywords that activate this skill. Click one to copy it.

This skill does not provide trigger words.

The downloaded .skill package contains the following fields.
Field Description
formatFormat tag (skill/v1)
skill_idUnique skill ID
nameSkill name
versionVersion
descriptionDescription
categoryCategories (array)
trigger_wordsTrigger words
tagsTags
sourceSource
source_urlSource URL (this page)
exported_atExported at (set per download)
system_promptSystem prompt body
model_configModel config: provider / model / temperature / max_tokens / top_p
examplesExamples
install_guideImport guide for Coze / Dify / Claude / custom frameworks
The same skill can be exported in different platform formats.
.skill Standard format with system_prompt and model_config, ready for any agent framework Download
.skillpro Enhanced format with scripts, tools, dependencies and hooks Download
.json Plain JSON export with system_prompt and model parameters only Download
Coze Markdown with frontmatter, for Coze platform import Download
Dify Dify DSL, import directly after creating an app Download

每日精选 Skill 推荐,免费送到你邮箱

输入邮箱,每天接收一个精选 AI Agent 技能推荐。完全免费,持续更新。

验证码 --

提交后我们会发送一封确认邮件,点击邮件里的链接才会开始收信。

完全免费,取消任意时间。我们不会发送垃圾邮件。