小编Ian*_*ley的帖子

带有打印联合值的怪癖

以下代码导致:

0.000000

10

在这种情况下,“数据”返回了什么?我知道n.data.idata并且n.data.fdata将是正确的用法,我只是好奇为什么整数值在这种情况下有效而浮点值却不起作用

#include<stdio.h>
#include<stdlib.h>

typedef struct node
{
    union container
    {
        int idata;
        float fdata;
    } data;
    struct node *next;
} Node;

int main()
{
    Node i = {.data.idata = 10};
    Node n = {.data.fdata = 10.0};
    printf("%f\n", n.data);
    printf("%d\n", i.data);

    printf("\nExiting program...\n");
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c printf unions

5
推荐指数
1
解决办法
1140
查看次数

glDebugMessageCallback 导致访问冲突(GLFW + GLAD)

我安装了 OpenGL 4.4 版本、相应的 4.4 核心 GLAD 版本和 GLFW 版本 3.2(在 Visual Studio 2015 中编辑)。我正在使用回调函数,详见https://learnopengl.com/#!In-Practice/Debugging

void APIENTRY glDebugOutput(GLenum source, GLenum type, GLuint id, GLenum severity, 
    GLsizei length, const GLchar *message, const void *userParam);
Run Code Online (Sandbox Code Playgroud)

我有以下功能:

GLFWwindow* init(int width, int height, const char* header) {
    GLFWwindow* window;

    glfwInit();
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);

    window = glfwCreateWindow(width, height, header, NULL, NULL);
    if (window == NULL) {
        glfwTerminate();
        throw std::runtime_error("Failed to create GLFW window.");
    }
    glfwMakeContextCurrent(window);
    glfwSetFramebufferSizeCallback(window, resizeCallback);

    if …
Run Code Online (Sandbox Code Playgroud)

c++ opengl glfw visual-c++

1
推荐指数
1
解决办法
3037
查看次数

标签 统计

c ×1

c++ ×1

glfw ×1

opengl ×1

printf ×1

unions ×1

visual-c++ ×1