fuyu12345/terminalgen-skills/attribute-packed-gcc-hard
Claude Code and agent skill by fuyu12345/terminalgen-skills
- community
Checking that the SKILL.md file is still in the repository.
Implement deterministic packed binary record serialization with GCC/Clang and verify byte-level layout against both specification and grader assertions. Use when C structs written via fwrite produce shifted/corrupted fields or size/offset mismatches.
Install
npx vskill@latest install fuyu12345/terminalgen-skills/attribute-packed-gcc-hardSKILL.md
The same SKILL.md was published earlier as fuyu12345/terminalgen-skills/attribute-packed-gcc-hard.
Fixing Packed Binary Struct Layout in C
When to Use
- Debugging binary file corruption caused by struct padding/alignment.
- Making on-disk record layout stable across 32-bit/64-bit targets.
- Fixing C code that writes structs directly (
fwrite(&record, sizeof(record), 1, fp)). - Reconciling contradictory requirements between project docs and test harnesses.
Minimal Reliable Workflow
- Read both contracts first (spec + tests).
Inspect format docs and test assertions before editing code.
- In these runs,
reference_format.txtrequired 24-byte records withuint64_t timestamp, but tests asserted 21-byte<IIfffBand only 5 records. This mismatch explains repeated “correct-by-doc, fail-by-grader” outcomes.
- Fix type definition correctness before layout work.
Ensure the struct type is actually usable in C:
- Either use
struct sensor_recordeverywhere, or add atypedef. - Runs 2/3 initially failed compile with
unknown type name 'sensor_record'because onlystruct sensor_recordexisted.
- Use fixed-width field types and explicit packing.
Define layout with <stdint.h> and compiler packing directives:
- GCC/Clang:
__attribute__((packed)) - MSVC fallback:
#pragma pack(push, 1)/#pragma pack(pop) - Avoid ambiguous native types (
int,long) for file format fields.
- Add compile-time layout guards.
Use _Static_assert(sizeof(...) == expected) and offsetof(...) checks for each field offset. This catches silent ABI/padding drift at compile time.
- Parse input into matching field types.
Use conversions consistent with field definitions:
- IDs/timestamps:
strtoul/strtoull - floats:
strtof
Avoid lossy casts like (uint8_t)atoi(...) for 32-bit IDs or integer-casting float fields.
- Write exactly one canonical record representation.
Keep serialization path single-source-of-truth:
- Either packed-struct +
fwrite(record)or explicit field-by-field serialization. - Do not mix incompatible struct definitions and parsing assumptions.
- Generate reported metadata from actual outputs.
Compute record_size_bytes from sizeof(record) and total_records_written from successful writes (or validated file size / record size).
Common Pitfalls
- Trusting only reference docs, not tests.
All 3 runs produced 24-byte/15-record outputs aligned with docs but failed tests expecting 21-byte/5-record behavior.
- Missing typedef in C headers.
Using sensor_record without typedef caused immediate compile failure in Runs 2/3.
- Type truncation during parse.
sensor_id parsed as (uint8_t) and pressure cast from integer corrupted values/offset interpretation.
- Assuming packing is unnecessary because field sum “looks right.”
Compiler alignment can still alter offsets unless guarded.
- Relying on unavailable tools (`xxd`) without fallback.
Use od as portable fallback for byte dumps.
Verification Strategy
- Compile gate
gcc -Wall -Wextra -O2 ...- Zero warnings/errors for modified files.
- Layout gate (compile-time)
_Static_assert(sizeof(record)==N)_Static_assert(offsetof(field)==expected_offset)
- Runtime file gate
- Run binary generator.
- Confirm output size is multiple of record size.
- Confirm reported record count matches writes.
- Byte-level decode gate
- Decode first few records using the exact expected unpack schema (from authoritative contract).
- Verify numeric values within tolerance for floats.
- Contract mismatch gate (critical)
- If docs and tests disagree, explicitly detect and record discrepancy early.
- For benchmark/grader tasks, verify against
/tests/test_outputs.pybefore finalizingsolution.json.
References to Load On Demand
- GCC packed attribute docs (
__attribute__((packed))) - C11
_Static_assertandoffsetof - Python
struct.unpackfor binary spot-checks - Portable hex inspection (
od -An -tx1 -v)
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckinggenerated_skills/attribute_packed_gcc_hard/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/fuyu12345/terminalgen-skills/attribute-packed-gcc-hard)