Near and Far pointer error in C code

Asked

Viewed 177 times

-2

Code compilation error in C, with Near and Far pointers

#include <stdio.h>

void main(void) {

    char *titulo_near = "Bíblia do Programador C/C++, do Jamsa!";
    char far *titulo_far = "Bíblia do Programador C/C++, do Jamsa!";

    printf("Título do livro: %Ns\n", titulo_near);
    printf("Título do livro: %Fs\n", titulo_far);

}

Result after trying to compile in GCC compiler

erros do código

  • Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful to you. You can also vote on any question or answer you find useful on the entire site.

2 answers

3

Throw away this book. He talks about a non-standard C for an architecture that is no longer used, as well as containing several errors, nor wasting time with it. Adopt a modern and correct book.

  • I have 2 books here, the one from the Bible and the other from the 6th edition of Deitel C, but I didn’t like the one from Deitel C, I didn’t like the one from the Bible much either, but among the 2 I found the Bible better at first. Got some to recommend ?

  • 1

    I don’t like any but Deitel is useful, this is useless and harmful.

  • Unfortunately GCC is still used in Computer Science courses... but never let college or college get in the way of your education.

  • @Renan what’s wrong with GCC?

  • @Maniero ops, my interpretation problem! I thought the criticism about the book extended to the compiler as well. I do not program nor am so fluent in C and ended up speaking badly of something I almost do not understand. I apologize.

  • The book is based on compilers from the 80’s.

Show 1 more comment

0

Hello! The book Programming in C/C++ "The Bible" is, in my opinion, an excellent book but, because it is an "old book (1999, as well as the book C Complete and Total)", it uses many resources that are outdated, whether it’s because of modifications to hardware technologies or upgrades to the C/C++ programming language, I recommend reading it after you have an initial knowledge of the language, as well, whenever you find something strange and/or a command that doesn’t work properly, do a search on the net or pass stackoverflow, plus the book contains a very good didactic and was once considered one of the best on the subject.

Below is an explanation taken from the net:

In the past, x86 processors supported only one mode of operation, called real mode. In real mode the memory was divided into segments, with fixed size of 64kb. Programming was a big challenge. The address bus was capable of carrying only 20 bits at a time, so there was a memory addressing limit of 1MB (2 20). This 1MB memory was divided into 16 segments of 64 Kb each. A segment was divided into displacements (Offset).

The memory was addressed in two parts: Segment:Offset. So, to access a certain region, we first put the address of the Segment and then a position within the segment, which is the Offset.

Ex: 0007:7B90

Well, I explained a lot, but so far I didn’t say anything about the NEAR and FAR pointers... but this explanation was necessary before :).

A NEAR pointer occupied 2 bytes and could access positions only within a segment (64kb). In fact, a NEAR pointer stored the Offset.

A FAR pointer occupied 4 bytes and was used to access an Offset in any segment. 2 bytes were used to address the segment and the other 2 bytes were used for offset.

HUGE pointers are very similar to FAR pointers, but have some advantages. In logical comparisons, for example, segment and offset are compared, while only offsets are compared in the case of FAR pointers. The downside is that addressing with a HUGE pointer is a little slower.

The use of each pointer depended on the memory model used (SMALL, TINY, LARGE, MEDIUM, etc.). The memory model specified how the code segment and data segment were structured.

The declaration of these pointers (NEAR, FAR and HUGE) are not part of the ANSI C standard and are not portable (they depend on the x86 platform).

Segmented memory is a thing of the past; running in protected mode, we now have all the available memory, in a model known as flat-memory. The distinction between NEAR, FAR and HUGE pointers is no longer required. Since the memory is no longer segmented, a pointer (which in this case is a NEAR) is sufficient to access any position (in rare cases a FAR pointer is still required... to access the buffer frame for example). Today, CS, DS, SS point to the same 'segment'.


I hope I helped, I am also an apprentice of C/C++/C#, I have this book since the year 2000 and I like it very much.

Hugs and good luck on the journey!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.