Why this program with near pointer doesn't work?

Debojit Acharjee 455 Reputation points
2023-07-28T14:55:48.9033333+00:00

Why this program with near pointer doesn't work on VS Code?

#include <stdio.h>
 
int main()
{
    // declaring a near pointer
    int near* ptr;
 
    // size of the near pointer
    printf("Size of Near Pointer: %d bytes", sizeof(ptr));
    return 0;
}

Output:

User's image

Developer technologies | C++
Developer technologies | Visual Studio | Other
Developer technologies | C#
{count} votes

Accepted answer
  1. RLWA32 49,636 Reputation points
    2023-07-28T15:30:21.41+00:00

    NEAR and FAR pointers are from the dim past before the advent of the flat address space that is used in modern systems. They remain in the headers for compatibility purposes so that old code isn't broken but they have no meaning today.

    1 person found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Castorix31 90,686 Reputation points
    2023-07-28T15:19:24.1533333+00:00

    In VS 2022, for "near" :

    #include <windows.h>
    #include <stdio.h>
    
    0 comments No comments

  2. Bruce (SqlWork.com) 78,086 Reputation points Volunteer Moderator
    2023-07-28T15:50:10.8033333+00:00

    Because you are using a compiler (like most) that does not support these keywords.

    near and far are custom keywords for an old windows intel c compiler and are used for accessing segmented memory. Few C/C++ compilers support these keywords any more as this hardware is fairly obsolete.

    you really should not use these unsupported keywords. The windows.h include define them as blank (so they basically are removed), so if you add windows.h your code will compile, but really you should not use them.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.