Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Unexpected behavior of unsized array defaults

Aperta
#1,959 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
45/100
Tipo di issue
Documentazione
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
cpp

Direzione di ricerca

Inizia dalla sezione della specifica del linguaggio OSL che descrive i valori predefiniti degli array senza dimensione, quindi confronta il comportamento segnalato in testshade e oslinfo con il parser di shader C++ esistente e il test unitario. Il lavoro è completato quando la specifica documenta chiaramente il valore predefinito di lunghezza uno per {} negli array senza dimensione e tutte le aspettative di test pertinenti sono state aggiornate.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Consider the following shader, in particular the declaration of the unsized array param:

shader test(int param[] = {})
{
    printf("array length %d\n", arraylength(param));
}

When running this in testshade, it prints:

array length 1

I think most people would reasonably expect that the {} in the declaration would produce a default array of length zero for param, so the resulting array with a single entry is surprising.

If a shader writer authored a for loop, for example, that did something for each value of an input array, e.g.:

shader test(int param[] = {})
{
    for (int i=0; i < arraylength(param), i++) {
        doStuff(param[i]);
    }
}

They might be surprised that their shader is executing doStuff() even when nothing is connected to param. In practice, however, we have worked around this behavior by guarding the for loop behind something like isconnected(param).

The peculiar behavior of unsized arrays makes sense, however, when considering that it's impossible to declare a fixed size array of length zero in OSL. Therefore, the best fix for this issue might be little more than adding a disclaimer in the section of the OSL language spec describing unsized array defaults.

As a footnote, we stumbled on this issue because we have a unit test that verifies the default input parameters of a set of C++ shaders and OSL shaders match, in order to prevent code drift. oslinfo always returned defaults of arrays of length one for the OSL shaders with unsized array parameters while our C++ shader parser produced zero-length arrays.

Lingua principale
C++
Stelle
2.3k
Fork
415
Merge medio
2g 14h
PR unite (30g)
13

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di AcademySoftwareFoundation/OpenShadingLanguage

Tutte le issue di AcademySoftwareFoundation/OpenShadingLanguage

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.