LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-31-2006, 07:22 PM   #16
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115

the size of int and int* are not always the same. In x86_64 systems, int is 4 bytes but int* is 8 bytes.
 
Old 08-31-2006, 07:31 PM   #17
debiant
Member
 
Registered: Jul 2006
Distribution: Source Mage 0.9.6
Posts: 196

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by tuxdev
the size of int and int* are not always the same. In x86_64 systems, int is 4 bytes but int* is 8 bytes.
In this instance would you want to cast the pointer then or is that why it is dangerous?

Or more appropriately p = malloc(sizeof(int)); will send a 4 byte address to p to store, what about the other 4?

Last edited by debiant; 08-31-2006 at 07:36 PM.
 
Old 08-31-2006, 07:48 PM   #18
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
Originally Posted by debiant
In this instance would you want to cast the pointer then or is that why it is dangerous?

Or more appropriately p = malloc(sizeof(int)); will send a 4 byte address to p to store
A 8 bytes address actually, if this a 64 bit CPU.
Quote:
what about the other 4?
They do not exist.
 
Old 08-31-2006, 07:51 PM   #19
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
The size of pointers vs primitives isn't the reason not to cast. The cast shuts up the compiler in -Wall mode so it can't complain that malloc doesn't exist yet. In C++ OTOH, the cast is required, but that doesn't matter here.
 
Old 08-31-2006, 08:26 PM   #20
debiant
Member
 
Registered: Jul 2006
Distribution: Source Mage 0.9.6
Posts: 196

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by jlliagre
A 8 bytes address actually, if this a 64 bit CPU.

They do not exist.
What is the point of a 64 bit address for a 32 bit integer?
 
Old 08-31-2006, 08:38 PM   #21
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Well, you can have 4 billions times more.

Also: what is a point of a 32 bit address for a 8 bit byte ?

Last edited by jlliagre; 08-31-2006 at 08:41 PM.
 
Old 09-01-2006, 12:24 AM   #22
debiant
Member
 
Registered: Jul 2006
Distribution: Source Mage 0.9.6
Posts: 196

Original Poster
Rep: Reputation: 30
I'll study up because I don't seem to comprehend storing a 16 bit or 32 bit value in a 64 bit address.
 
Old 09-01-2006, 12:39 AM   #23
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
Quote:
Originally Posted by debiant
I'll study up because I don't seem to comprehend storing a 16 bit or 32 bit value in a 64 bit address.
when you are talking about a pointer you are not storing a 16 or 32 bit value in a 64 bit address, you are storing the address of a memory location that holds the 16 or 32 bit value.

the actual memory location that is holding the data is still at the size of the type. but any ptrs that would point to that location are the size of a ptr, which is sized to address the entire address space, which is 64 bit.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple is efficient ???? Maybe/Maybe not ! bigjohn General 21 07-08-2005 10:27 AM
a more efficient set up dr_zayus69 Linux - Newbie 3 12-03-2004 09:47 AM
java test if string in string array is null. exodist Programming 3 02-21-2004 01:39 PM
Most efficient cost effective way??? nor General 3 06-26-2003 11:39 AM
storing and comparing a string Randall Programming 18 03-10-2003 10:05 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:16 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration