Thread: decleration

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    9

    decleration

    Code:
    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    char far *s1,*s2;
    clrscr();
    printf("%d %d",sizeof(s1),sizeof(s2));
    getch();
    }

    the output is 4,2 how?

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by britto116 View Post
    the output is 4,2 how?
    Possibly because of some typo involving the word "far". That code should not even compile as is.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Registered User
    Join Date
    Sep 2007
    Posts
    1,012
    There are a few problems with the code (void main, %d for size_t), but "far" is not necessarily one of them. On some systems (OP is almost certainly on MS-DOS; or at least using a 16-bit compiler on an x86), you have different types of pointers due to the underlying architecture. A normal pointer on such a system points into the current segment, and thus is only 16 bits. A far pointer can point to another segment, and so needs to be larger, to hold both which segment it's pointing to and the offset inside of the segment. Thus you have 16-bit "normal" pointers and 32-bit far pointers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problems with variable in class decleration prog.
    By ronin_spirit in forum C++ Programming
    Replies: 5
    Last Post: 12-15-2008, 09:55 PM
  2. multiple types in one decleration
    By hebele in forum C++ Programming
    Replies: 1
    Last Post: 10-17-2004, 07:23 AM
  3. about decleration?
    By kuwait in forum C++ Programming
    Replies: 5
    Last Post: 10-08-2003, 08:47 AM

Tags for this Thread