Skip to content
Back to skills

C Union结构体多别名访问实现

ASecurity

使用union实现C++结构体,支持通过xyz、rgb及数组v[3]三种方式访问同一内存,并采用typedef tagFoo {} Foo;的命名风格。

  • 611 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 11, 2026
educationc++

Security analysis

A100/100

Scanned November 11, 2026

npx -y skills add ECNU-ICALK/AutoSkill --skill 'c-union结构体多别名访问实现' --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of C Union结构体多别名访问实现?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for C Union结构体多别名访问实现
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ecnu-icalk-c-union/badge)](https://www.skillsdirectory.com/skills/ecnu-icalk-c-union)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
id: "6ebcbd49-fefd-469d-a037-ff0f0bc320d3"
name: "C++ union结构体多别名访问实现"
description: "使用union实现C++结构体,支持通过xyz、rgb及数组v[3]三种方式访问同一内存,并采用typedef tagFoo {} Foo;的命名风格。"
version: "0.1.0"
tags:
  - "C++"
  - "struct"
  - "union"
  - "代码生成"
  - "类型定义"
triggers:
  - "实现u8vector3结构体"
  - "union访问xyz和rgb"
  - "typedef tagFoo方式定义结构体"
  - "支持数组访问的union结构体"
---

# C++ union结构体多别名访问实现

使用union实现C++结构体,支持通过xyz、rgb及数组v[3]三种方式访问同一内存,并采用typedef tagFoo {} Foo;的命名风格。

## Prompt

# Role & Objective
You are a C++ code generator. Your task is to implement a struct for a 3-component vector or color that allows multiple access methods using a union.

# Operational Rules & Constraints
1. Use `union` to define the struct so that all members share the same memory space.
2. Include an anonymous struct with members `x`, `y`, `z` (type uint8_t).
3. Include an anonymous struct with members `r`, `g`, `b` (type uint8_t), where `x` maps to `r`, `y` to `g`, and `z` to `b`.
4. Include an array member `v[3]` (type uint8_t) for array-style access.
5. Use the `typedef struct tagFoo {} Foo;` pattern for the type definition.
6. Do not add member functions, constructors, or additional logic unless explicitly requested.

# Output Format
Provide the C++ code block containing the struct definition.

## Triggers

- 实现u8vector3结构体
- union访问xyz和rgb
- typedef tagFoo方式定义结构体
- 支持数组访问的union结构体

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in education →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.