Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
IT Security ToolsGitHub Release: google/clusterfuzz v2.41.2 (24.09.2026)(24.09.2026 um 14:57 Uhr)
IT Security NachrichtenNew Browser Guard features add protection before and after you click(24.09.2026 um 14:45 Uhr)
IT Security NachrichtenMeta brings Private Processing privacy protections to AI glasses(24.09.2026 um 14:44 Uhr)
IT Security NachrichtenTesla FSD Fails Belgian Safety Tests(24.09.2026 um 14:56 Uhr)
Sicherheitslücken (CVE)CISA Charts New "Quality Era" for Global CVE Program(24.09.2026 um 14:50 Uhr)
IT Security NachrichtenThe cost of intelligence?(24.09.2026 um 15:00 Uhr)
IT Security ToolsGitHub Release: google/clusterfuzz v2.41.2 (24.09.2026)(24.09.2026 um 14:57 Uhr)
IT Security NachrichtenNew Browser Guard features add protection before and after you click(24.09.2026 um 14:45 Uhr)
IT Security NachrichtenMeta brings Private Processing privacy protections to AI glasses(24.09.2026 um 14:44 Uhr)
IT Security NachrichtenTesla FSD Fails Belgian Safety Tests(24.09.2026 um 14:56 Uhr)
Sicherheitslücken (CVE)CISA Charts New "Quality Era" for Global CVE Program(24.09.2026 um 14:50 Uhr)
IT Security NachrichtenThe cost of intelligence?(24.09.2026 um 15:00 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

Zig vs Go: generics

(you can find previous post about same topic here) Go introduces generics only starting from version 1.18 following numerous requests from the community: from this version, Go allows parameterizing the types of functions and structures in…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

(you can find previous post about same topic here)



Go introduces generics only starting from version 1.18 following numerous requests from the community: from this version, Go allows parameterizing the types of functions and structures in order to avoid code redundancy.

Zig does not provide a syntax for generics but uses one of its peculiar features, namely the generation and/or manipulation of code at compile time (metaprogramming) with the use of the comptime keyword. The advantage is to obtain a binary without overhead for type checking during runtime.





Using generics in functions



Let's see how to define a function that accepts multiple types




// Go
func doubleNumber[T constraints.Integer | constraints.Float](a T) T {
return a * T(2)
}
...
doubledFloat := doubleNumber[float32](5.3)
fmt.Println(doubledFloat)
// type parameter inferred
doubledInteger := doubleNumber(5)
fmt.Println(doubledInteger)









// Zig 
fn doubleNumber(comptime T: type, a: T) T {
return a * 2;
}
...
const doubledFloat = doubleNumber(f32, 5.3);
std.debug.print("{}\n", .{doubledFloat});
const doubledInteger = doubleNumber(i32, 5);
std.debug.print("{}\n", .{doubledInteger});






Note that in Go the generic is defined through its constraints which are interfaces that allow the compiler to check if a type does not respect the interface, while Zig evaluates any compilation errors during the compile-time phase when it actually tries to create the function for the type indicated by the caller.






Using generics in structure definitions



In Go, also for structs we can indicate one or more types with the same syntax and rules we use for functions.




// Go
type Stack[T any, Q any] struct {
Items []T
AlterItems []Q
Index int
}
...
intStack := Stack[int8, float32]{
Items: []int8{1, 2, 3, 4, 5},
AlterItems: []float32{1.1, 2.1, 3.1, 4.7, 5.3},
Index: 4,
}
fmt.Println(
intStack.Items[intStack.Index],
intStack.AlterItems[intStack.Index]
)

strStack := Stack[string, bool]{
Items: []string{"hello", "gophers"},
AlterItems: []bool{false, true},
Index: 0,
}
fmt.Println(
strStack.Items[strStack.Index],
strStack.AlterItems[strStack.Index]
)






In Zig, to obtain a struct with parameterized type fields, use a function that returns type and is therefore resolved at compile time.




// Zig 
fn Stack(comptime T: type, comptime Q: type) type {
return struct {
items: []const T,
alterItems: []const Q,
index: usize,
};
}
...
const intArr = [_]i32{ 1, 2, 3, 4, 5 };
const floatArr = [_]f32{ 1.1, 2.1, 3.1, 4.7, 5.3 };
const intStack = Stack(i32, f32){
.items = intArr[0..],
.alterItems = floatArr[0..],
.index = 4,
};
std.debug.print("{d} {d}\n",
.{ intStack.items[intStack.index],
intStack.alterItems[intStack.index]
});

const strArr = [_][]const u8{ "hello", "ziguanas" };
const boolArr = [_]bool{ false, true };
const strStack = Stack([]const u8, bool){
.items = &strArr,
.alterItems = &boolArr,
.index = 1,
};
std.debug.print("{s} {}\n",
.{ strStack.items[strStack.index],
strStack.alterItems[strStack.index]
});









Structs as generics



In Go, constraints are interfaces, so in a function that accepts structs as parameters, they must at least implement the methods used within the function block




type IdTrackable interface {
GetID() string
}

type Article struct {
ID string
Name string
Category string
}
func (a Article) GetID() string { return a.ID }

type SKU struct {
ID string
ArticleID string
Available bool
}
func (s SKU) GetID() string { return s.ID }

func findById[T IdTrackable](items []T, id string) (*T, error) {
for _, item := range items {
if item.GetID() == id {
return &item, nil
}
}
return nil, errors.New("not found")
}
...
articles := []Article{
{
ID: "a1",
Name: "Laptop",
Category: "Electronics",
},
{
ID: "a2",
Name: "Book",
Category: "Education",
},
}

article, err := findById(articles, "a1")
if err == nil {
fmt.Printf("Found article: %+v\n", *article)
}






In Zig, this function with the generic will be resolved and duplicated at compile time as many times as a different type is passed in its call.




// Zig
const Article = struct {
id: []const u8,
name: []const u8,
category: []const u8,
};

const SKU = struct {
id: []const u8,
articleId: []const u8,
available: bool,
};

fn findById(comptime T: type, items: []const T, idx: []const u8) !T {
for (items) |item| {
if (std.mem.eql(u8, @field(item, "id"), idx)) {
return item;
}
}
return error.NotFound;
}
...
const articles = [_]Article{
.{
.id = "a1",
.name = "Laptop",
.category = "Electronics",
},
.{
.id = "a2",
.name = "Book",
.category = "Education",
},
};

const art = try findById(Article, &articles, "a2");
std.debug.print("Found article: {}\n", .{art});






The use of metaprogramming proposed by Zig, with its own syntax and rules, reveals many other potentials beyond the resolution of generics that are currently not achievable with Go.

SOC Incident Playbook: Vulnerability Remediation & Verification
title: Detect Exploitation - Zig vs Go: generics
id: fff067e3-d322-4b61-ab38-36b58a8039d0
status: experimental
description: Automatisch generierte SIEM-Erkennungsregel basierend auf CTI Intelligence
references:
  - https://tsecurity.de/
author: iShareStuff CTI Automated Detection Engine
date: 2026-09-24
logsource:
  category: network_connection
  product: any
detection:
  selection:
      CommandLine|contains:
        - 'exploit'
  condition: selection
falsepositives:
  - Legitime administrative Zugriffe oder Penetrationstests
level: high
tags:
  - attack.initial_access
rule CTI_Threat_Indicator {
    meta:
        author = "iShareStuff CTI Automated Detection Engine"
        date = "2026-09-24"
        description = "YARA Signature for "
    strings:
        $str = "Zig vs Go: generics" ascii wide
    condition:
        any of them
}
tsecurity.de Cognitive Threat RAG
Fokus-Vektor:

Kognitive Analyse für identifizierte Bedrohung: Erhöhte Bedrohungslage im Bereich Zig vs Go: generics.... Basierend auf 368k Vektor-Korrelationen werden sofortige Isolationsmaßnahmen für betroffene Endpunkte empfohlen.

🛡️ Angriffsfläche & Exposure

Netzwerk/Remote-Zugriff ohne Vorauthentifizierung möglich.

Empfohlene Sofortmaßnahmen
  • 1. Perimeter-Inspektion: Relevante Portfreigaben und exponierte Endpunkte unverzüglich scannen.
  • 2. Patch-Applikation: Hersteller-Hotfix einspielen oder betroffene Daemons in isolierte DMZ-Segmente überführen.
  • 3. Telemetrie & EDR-Alerts: Prozessaufrufe und Child-Processes auf anomale Shell-Spawns überwachen.
🔗 Semantisch verwandte Zero-Days MariaDB 11.7 VEC
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Zig vs Go: generics

Thematisch verwandte Begriffe: generics · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-97152 | Nanomsg versions 0.5-beta through 1.x before 1.2.3 has a remotely exploi…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel TTP ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick