Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Unexpected behavior of unsized array defaults

Đang mở
#1,959 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
45/100
Loại issue
Tài liệu
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
cpp
Lĩnh vực
compilers, documentation

Hướng nghiên cứu

Bắt đầu với phần đặc tả ngôn ngữ OSL mô tả các giá trị mặc định của mảng không có kích thước, sau đó so sánh hành vi được báo cáo trong testshade và oslinfo với trình phân tích shader C++ hiện có và bài kiểm thử đơn vị. Công việc được hoàn tất khi đặc tả ghi rõ giá trị mặc định có độ dài một cho {} trên các mảng không có kích thước và mọi kỳ vọng kiểm thử liên quan đã được cập nhật.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
C++
Star
2.3k
Fork
415
Merge trung bình
3 ngày 16 giờ
Pull request đã merge (30 ngày)
10

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của AcademySoftwareFoundation/OpenShadingLanguage

Tất cả issue của AcademySoftwareFoundation/OpenShadingLanguage

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.