473,396 Members | 1,757 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,396 software developers and data experts.

Address of an integer variable

Consider the below initialization of x.

Expand|Select|Wrap|Line Numbers
  1. int x = 0x01234567;
If x is stored in RAM as given below, what would be the address x in both case?

[IMG]C:\Users\101781\Desktop\lb[/IMG]
(if image is invisible please follow this link)

Assume that size of integer is 4 byte.
Nov 25 '14 #1

✓ answered by donbock

I think which particular byte the address points at is [compiler] implementation-dependent; but any rational compiler writer will match the conventions of the processor that the code runs on.

If you're compiling code for a processor that expects the address to point at the byte with the lowest address regardless of whether that's the LSB or MSB then that's probably what the compiler will do.

If you're compiling code for a processor that expects the address to point at the LSB (or MSB) regardless of whether that's the highest of lowest address then that's probably what the compiler will do.
From C: A Reference Manual by Harbison & Steele (emphasis added)...
"The address of a larger piece of storage -- one used to hold an integer or a floating-point number -- is typically the same as the address of the first character in the larger unit. The "first" character is the one with the lowest address."
A further complication arises if the processor has a segmented memory architecture (e.g, far and near pointers) or if an MMU is performing address translation. (Although this complication won't change which is the "first" character in the larger unit.)

4 1366
I got an answer here
Nov 25 '14 #2
weaknessforcats
9,208 Expert Mod 8TB
The address of x is always the address of the start (LSB) of the memory area occupied by the int.
Nov 25 '14 #3
donbock
2,426 Expert 2GB
I think which particular byte the address points at is [compiler] implementation-dependent; but any rational compiler writer will match the conventions of the processor that the code runs on.

If you're compiling code for a processor that expects the address to point at the byte with the lowest address regardless of whether that's the LSB or MSB then that's probably what the compiler will do.

If you're compiling code for a processor that expects the address to point at the LSB (or MSB) regardless of whether that's the highest of lowest address then that's probably what the compiler will do.
From C: A Reference Manual by Harbison & Steele (emphasis added)...
"The address of a larger piece of storage -- one used to hold an integer or a floating-point number -- is typically the same as the address of the first character in the larger unit. The "first" character is the one with the lowest address."
A further complication arises if the processor has a segmented memory architecture (e.g, far and near pointers) or if an MMU is performing address translation. (Although this complication won't change which is the "first" character in the larger unit.)
Nov 25 '14 #4
Is endianness of modern PCs Big-Endian?
Nov 26 '14 #5

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

Similar topics

2
by: Roger Lord | last post by:
I am constructing a string in my program and then trying to use it to get the value of an integer variable whose label looks like that string. I can't figure out how to do it. For example: Dim...
12
by: obdict | last post by:
Hello, I have a simple C question regarding scanf() /* What happens if user inputs a char when he/she is supposed * to input an integer? */ #include<stdio.h> int main(void){ int n;
2
by: awrightus | last post by:
I am trying to incorporate a integer variable with a vb.net datetime literal. For example: Dim Jan1 As DateTime = (#1/1/2006#) would be a literal for January 1st of this year. But I have a...
3
by: tirrell payton | last post by:
Hello all, I have a question about the concatenation operator in C#. For example, I want to concatenate an integer variable to a control. I have an integer, i. I have checkboxes, checkbox0 -...
12
by: Monty | last post by:
Hope this is an easy one: How can I bind a text on a form to a an integer variable? Possible? Thanks!
3
by: DeerGuy | last post by:
This is a really, really simple question, but I so new to VBA, that I have to ask. I have an integer variable that I want to perform some actions on depending upon its value. Is the following...
34
by: Cuthbert | last post by:
Hi folks, I am trying to find a more efficient way to count "How many bits are '1' in a integer variable?". I still have no idea to count the bits except using a loop and "if" statements....
2
by: Mike OKC | last post by:
VB.NET 2003 I'm new to VB.NET, so this should be an easy fix. My integer variable showing &HA when I hover the mouse pointer over the variable, and also shown in Locals, Name: intLoop Value: &HA...
2
by: zamuel | last post by:
I have fairly simple problem. I have a form which shows email address from database on label called 'email'. This address shows as a mailto link, which opens outlook normally. Because the address...
4
by: hhak | last post by:
Hi all, Im pretty new to C#, im trying to assign a combobox selected value to a int variable. int number; combobox has items added (1,2,3,4,...9) when i select a number from the combobox i...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...

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.