473,399 Members | 2,159 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

how comes the two addresses equal while the digit are different

Expand|Select|Wrap|Line Numbers
  1.  
  2. void main(){
  3.  
  4. int far *p=(int *)0X70230000;
  5.  
  6. int far *q=(int *)0XB0210000;
  7.  
  8. int near *x,near*y;
  9.  
  10. x=(int near *)p;
  11.  
  12. y=(int near *)q;
  13.  
  14. if(x==y)
  15.  
  16. printf("Both pointer are equal");
  17.  
  18. else
  19.  
  20. printf("Both pointer are not equal");
  21.  
  22.  
  23. }
  24.  
Output: Both pointers are equal
Apr 3 '11 #1

✓ answered by Banfa

As far (no pun intended) as I am aware near and far have only ever been used in 16 bit Windows.

In 32 bit windows I believe they are defined to nothing so on a 32 bit system that will produce "Both pointer are not equal" which is bourne out when I compile it with MinGW.

If you compiled it on a 16 bit windows platform then you must take account of the fact that near pointers were 16 bits and far pointers where 32 bits (to access memory in extended memory segments), consisting of a 16 bit segment and a 16 bit offset.

When you convert your far pointers to near pointers you drop the segment and are left with the offset (the lower 16 bits). Looking at your addresses the lower 16 bits of both of 0x0000 so under conversion to near pointers they are equal. Of course at least 1 if not both of them now no longer points to the right place either.

3 1510
weaknessforcats
9,208 Expert Mod 8TB
If I remove all that far/near stuff the pointers are not equal.
Apr 3 '11 #2
donbock
2,426 Expert 2GB
far and near are not part of Standard C, thus their operation is implementation-dependent.

In general, a near pointer value provides only the lower bits of the address; the upper bits are assumed. How many bits come from the near pointer value and how many are assumed could vary between implementations. In your case I suppose the break comes somewhere in the lowest 17 bits.
Apr 4 '11 #3
Banfa
9,065 Expert Mod 8TB
As far (no pun intended) as I am aware near and far have only ever been used in 16 bit Windows.

In 32 bit windows I believe they are defined to nothing so on a 32 bit system that will produce "Both pointer are not equal" which is bourne out when I compile it with MinGW.

If you compiled it on a 16 bit windows platform then you must take account of the fact that near pointers were 16 bits and far pointers where 32 bits (to access memory in extended memory segments), consisting of a 16 bit segment and a 16 bit offset.

When you convert your far pointers to near pointers you drop the segment and are left with the offset (the lower 16 bits). Looking at your addresses the lower 16 bits of both of 0x0000 so under conversion to near pointers they are equal. Of course at least 1 if not both of them now no longer points to the right place either.
Apr 4 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Ben | last post by:
Hi all, I'm posting this to comp.lang.php and comp.protocols.tcp-ip. I'm quite new to php. I made a simple test page in php with "_SERVER" and "_SERVER" server variables. I uploaded my page...
17
by: Andrew McLean | last post by:
I have a problem that is suspect isn't unusual and I'm looking to see if there is any code available to help. I've Googled without success. Basically, I have two databases containing lists of...
3
by: Jennifer | last post by:
I'm running SQL query to caluclate projected food costs. The calculation is this: (ReportedFoodSales / PlanFoodSales) * FullPlanFoodSales Seems simple enough to me. Using the following...
87
by: j0mbolar | last post by:
I've read in the standard that addresses basically can't be interpreted as integers. If they can, it is implementation defined behavior. However, if they can't be viewed as integers in any sense...
3
by: Kermit Piper | last post by:
Hello everyone, OK, let me try and explain again please. Here is what I'm trying to do. I have a 12-digit (UPC-A) javascript validation script which works great. All I need now is a similar...
13
by: Kantha | last post by:
Hi all, I have declared an Union as follows typedef union { struct interrupt_bits { unsigned char c_int_hs_fs_status : 1, c_setup_intflag : 1,
11
by: balakrishnan.dinesh | last post by:
hi frnds, Im having two 20digit numbers, But while comparing those it is giiving wrong ouput in javascript. for example here is my code, my secanrio is , ~ If first 20 digit number is...
7
by: Jay | last post by:
I want to check if a character is a decimal digit (0-9). I've found Char.IsNumber() and Char.IsDigit() but couldn't work out from Help how they differ. Also, do I need to worry about how digits...
43
by: davidkoree | last post by:
I mean not about cookie. Does it have something to do with operating system or browser plugin? I appreciate any help.
0
by: nancylife | last post by:
When developing web report, many developers use VMware to simulate different operating systems on a same server. Then, they can realize cross-platform deployment and debug of web report. According to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.