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

Changing default sizes of data types

Is there a way to get different return values for sizeof(int*) etc.
Right now, it is 4 on my machine...I want it to return, say, 3.
Basically, I'd like to play around with alignment issues that might
arise with memory allocation if sizeof(int) != sizeof(int*).

Thanks in advance
Anirudh
Nov 14 '05 #1
3 893
Anirudh <an*******@gmail.com> wrote:
Is there a way to get different return values for sizeof(int*) etc.
Right now, it is 4 on my machine...I want it to return, say, 3.
Write your own compiler;-)
Basically, I'd like to play around with alignment issues that might
arise with memory allocation if sizeof(int) != sizeof(int*).


There are easier way to do unaligned access than fiddling with the
compiler, e.g (untested and error checking omitted for obvious
reasons;-)

char *c = malloc( 2 * sizeof( int ) );
int i;

for ( i = 0; i < sizeof( int ); i++ )
{
* ( int * ) ( c + i ) = i;
print( "%d: %d\n", i, * ( int * ) ( c + i ) );
}

If this crashes with a bus error (or whatever it's called on your
system) you have a system that won't allow unaligned access. If it
does not crash te system the alternatives are either that unaligned
accesses are not flagged or that you have sizeof(int) == 1.

Regards, Jens
--
\ Jens Thoms Toerring ___ Je***********@physik.fu-berlin.de
\__________________________ http://www.toerring.de
Nov 14 '05 #2
In <b0**************************@posting.google.com > an*******@gmail.com (Anirudh) writes:
Is there a way to get different return values for sizeof(int*) etc.
Right now, it is 4 on my machine...I want it to return, say, 3.


Do you realise ALL the implications of changing the size of a data type?
Basically, you have a new implementation, needing its own library and
so on.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #3

"Anirudh" <an*******@gmail.com> wrote

Is there a way to get different return values for sizeof(int*) etc.
Right now, it is 4 on my machine...I want it to return, say, 3.
Basically, I'd like to play around with alignment issues that might
arise with memory allocation if sizeof(int) != sizeof(int*).

As others have siad, the only way to change the size of an int is to write
your own compiler.
However if the code is portable you should be able to compile it with a
different compiler and see if it still works. For example a lot of old DOS
compilers don't have sizeof(int) == sizeof(int *), so you should be able to
pick up code that makes this assumption.
Nov 14 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: David Fisher | last post by:
The most common sizes of integer types seem to be: 8 bits - signed char 16 bits - short 16 or 32 bits - int 32 or 64 bits - long Question #1: Does anyone know how common sizes other than...
4
by: Steven T. Hatton | last post by:
I mistakenly set this to the comp.std.c++ a few days back. I don't believe it passed the moderator's veto - and I did not expect or desire anything different. But the question remains: ISO/IEC...
26
by: Kip | last post by:
Greetings everyone, Is there anyone here who could point me to a page or pdf that has a list of the sizes of all of the C primitive data types on various implementations such as SPARC, x86,...
25
by: gamehack | last post by:
Hi all, I'm writing an application which will be opening binary files with definite sizes for integers(2 byte integers and 4 byte longs). Is there a portable way in being sure that each integer...
4
by: Dabbler | last post by:
Is there a table of sizes to use for SqlDbTypes with SqlParameter constructor such as: SqlParameter("@VanId", SqlDbType.Int, 4")); Not sure which types require a size and which ones can be left...
14
by: Michael Brennan | last post by:
Hi, I wonder if there is any good reason to let different systems have different sizes of short, int and long? I think that makes it harder to plan which type to use for your program. For...
43
by: JohnQ | last post by:
Are a default constructor, destructor, copy constructor and assignment operator generated by the compiler for a struct if they are not explicitely defined? I think the answer is yes, because...
7
oll3i
by: oll3i | last post by:
i want to change the values in two columns one colum is a combobox and the secons column is editable too i want to get the value of that second column and the value of combobox and sent that...
159
by: Bob Timpkinson | last post by:
Hi, I have a 32-bit machine... Is there anyway I can get gcc to use the following integer sizes? char: 8 bits short: 16 bits int: 32 bits long: 64 bits long long: 128 bits
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.