and still the prog...">

OpenGL includes OS X directives

I am a little confused why this code compiles. I leave the "necessary" #include <OpenGL/gl.h>and still the program can compile. How is this possible when my program calls functions from the GL library, not including them.

int main(int argc, char** argv)
{

    glClearColor(1.0,1.0,1.0,1.0);
    return 0;
}

I use this compilation command:

 gcc -framework GLUT -framework OpenGL test.c

I was on the assumption that adding -framework just points to the linker where the library is located, but I thought I still need the headers?

+3
source share
3 answers

C ( C99) . , , , , int. , , , undefined, . :

/* file1.c */
void foo(char a, char b) {
    /* doing something ... */
}

/* main.c */
int main(void) {
    char a = 'a', b = 'b';
    /* char variables are promoted to int 
       before being passed */
    foo(b, a); 
}

(char -> int, float -> double), , , , . b . node, , vararg functions prinft , (, void f(), ). , va_arg, . GCC , .

, .

: , , char literals (, 'a') int C

+3

glClearColor , . :

gcc -o test -Wall -W test.c -framework GLUT -framework OpenGL

glClearColor. - , undefined. glClearColor , .

, , , , , ++. , , C, , . ++, :

g++ -o test test.cpp -framework OpenGL

, gl.h, . GCC g++ ++, gcc C.

+5

This really refers to the classic fragment of the C & R hello world:
http://en.wikipedia.org/wiki/Hello_world#History

0
source

Source: https://habr.com/ru/post/1699348/


All Articles