Why this program with near pointer doesn't work?

Debojit Acharjee 425 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

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,404 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
9,938 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,441 questions
{count} votes

Accepted answer
  1. RLWA32 38,856 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 80,906 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) 52,496 Reputation points
    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