What does (int) mean in C programming

void problem3(void) {
    int overflowme[16];
    int x = (int) problem3; // x is the address of the first instr for problem3
    printf("hello world\n");
    overflowme[17] = x; 

I am wondering what (int) does in C programming.

+3
source share
6 answers

This is the type and tells the compiler, "Ignore the type that really has the problem3, and treat it as if it were entered as an int."

In this example, problem3 has a function pointer type, so usually the compiler will reject the program (using a function pointer when an integer is expected is usually a programmer error). Typing forces a different interpretation — the programmer enters and says, “I know what I'm doing.”

+16
source

. problem3 , x.

, 3.

+2

cast - (problem3 ) .

C ( ++, " C" ), :

  • , - . , int.
  • . , float int , ( /), ( , ).

, ( ), ++ :

  • reinterpret_cast<>(), ,
  • static_cast<>(), ( )
  • const_cast<>(), , const volatile,
  • dynamic_cast<>(), ++ C. "" .

, . , . , , , C.

problem3 , - "" int. --int , ( ). , , , , problem3() , (ad-infinitum - ).

, "" problem3() , - it return , , , , , .

+1

, problem3 int int x

0

, .. /, . void (*) (void) int ( )

0

As others have noted, this is simply an explicit cast. It just changes the type of the variable to type int.

But from the code you posted, it looks like this function is preparing for a buffer overflow or something like that. What is the rest of this feature?

0
source

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


All Articles