01-20-2014
You must be on a 64-bit system. The way those have mostly worked out is that 'int' remains 32-bit, 'long int' becomes 64-bit, and pointers become 64-bit. On a 32-bit system, int, long int, and pointers are all 32-bit.
Subtracting two pointers from each other gives you a 64-bit integer, but %d expects a 32-bit integer. I think that would end up printing 0 for all numbers less than the 32-bit limit.
I would always use %ld to print pointer differences, just to be safe, since it'll work properly on both 32 and 64 bit systems.
Last edited by Corona688; 01-20-2014 at 02:50 PM..
This User Gave Thanks to Corona688 For This Post:
9 More Discussions You Might Find Interesting
1. Programming
void main()
{
int a={1,2,3,4,5,6,7,8,9,10};
int *p=a;
int *q=&a;
cout<<q-p+1<<endl;
}
The output is 10, how?
if we give cout<<q it will print the address, value won't print....
if we give cout<<p it will print the address, value won't print....
p has the base addr; q... (1 Reply)
Discussion started by: sarwan
1 Replies
2. UNIX for Dummies Questions & Answers
All ..
I am having a pointer array . And trying to store the addess into that pointer array . please see below the problem i faced
code:
int cnt1;
char *t_array;
char *f_array;
for(cnt1=0; cnt1<1000; cnt1++)
{
t_array =... (1 Reply)
Discussion started by: arunkumar_mca
1 Replies
3. Programming
If one wants to get a start address of a array or a string or a block of memory via a function, there are at least two methods to achieve it:
(1) one is to pass a pointer-to-pointer parameter, like:
int my_malloc(int size, char **pmem)
{
*pmem=(char *)malloc(size);
if(*pmem==NULL)... (11 Replies)
Discussion started by: aaronwong
11 Replies
4. Programming
Hi all,
Can anyone provide help with getting the right syntax regarding array/pointers in C in the following code? Can't locate a specific example which clarifies this...
Say I declare a typedef to an array of pointers to some type...
/**
* An array of ptrs to sections
*/
typedef... (4 Replies)
Discussion started by: gorga
4 Replies
5. Programming
i have an array like
#define NUM 8
....
new_socket_fd = accept(socket_fd, (struct sockaddr *) &cli_addr, &client_length);
char *items = {"one", "two", "three", "four", "five", "six", "seven", "eight"};
char *item_name_length = {"3", "3", "5", "4", "4", "3", "5", "5"};
... (1 Reply)
Discussion started by: omega666
1 Replies
6. Programming
if i create an array of pointers to a structure "struct node" as:
struct node *r;
and create "n" number of "linked lists" and assign it to the various struct pointers r using some function with a return type as structure pointer as:
r=multiplty(.......) /*some parameters*/
is... (2 Replies)
Discussion started by: mscoder
2 Replies
7. Shell Programming and Scripting
Hi guys,
Besides the points bellow, what would best practices for scripting be ?
1) set the PATH
2) unset the current environment (set -u ?)
3) (re)set the IFS to default value - space (IFS="" <- is this correct ?)
4) check the return code for each action inside the script (cd, rsync,... (1 Reply)
Discussion started by: da1
1 Replies
8. Programming
how to copy content of character pointer to character array in c programming..
char *num;
char name=num; (1 Reply)
Discussion started by: zinat
1 Replies
9. Programming
I am struggling with the pointer to 2D-array (cf: 2D array of pointers). Can anybody help me elaborate how the pointer x moves in the memory to access the individual of y, especially the high lighted lines?
I have talked to one of the curators of the forum, but I am still not quite clear.
Here... (1 Reply)
Discussion started by: yifangt
1 Replies
LEARN ABOUT SUNOS
id32_lookup
id32_alloc(9F) Kernel Functions for Drivers id32_alloc(9F)
NAME
id32_alloc, id32_free, id32_lookup - 32-bit driver ID management routines
SYNOPSIS
#include <sys/ddi.h>
#include <sys/id32.h>
uint32_t id32_alloc(void *ptr, int flag);
void id32_free(uint32_t token);
void *id32_lookup(uint32_t token);
INTERFACE LEVEL
Solaris architecture specific (Solaris DDI).
PARAMETERS
ptr any valid 32- or 64-bit pointer
flag determines whether caller can sleep for memory (see kmem_alloc(9F) for a description)
DESCRIPTION
These routines were originally developed so that device drivers could manage 64-bit pointers on devices that save space only for 32-bit
pointers.
Many device drivers need to pass a 32-bit value to the hardware when attempting I/O. Later, when that I/O completes, the only way the
driver has to identify the request that generated that I/O is via a "token". When the I/O is initiated, the driver passes this token to the
hardware. When the I/O completes the hardware passes back this 32-bit token.
Before Solaris supported 64-bit pointers, device drivers just passed a raw 32-bit pointer to the hardware. When pointers grew to be 64 bits
this was no longer possible. The id32_*() routines were created to help drivers translate between 64-bit pointers and a 32-bit token.
Given a 32- or 64-bit pointer, the routine id32_alloc() allocates a 32-bit token, returning 0 if KM_NOSLEEP was specified and memory could
not be allocated. The allocated token is passed back to id32_lookup() to obtain the original 32- or 64-bit pointer.
The routine id32_free() is used to free an allocated token. Once id32_free() is called, the supplied token is no longer valid.
Note that these routines have some degree of error checking. This is done so that an invalid token passed to id32_lookup() will not be
accepted as valid. When id32_lookup() detects an invalid token it returns NULL. Calling routines should check for this return value so that
they do not try to dereference a NULL pointer.
CONTEXT
These functions can be called from user or interrupt context. The routine id32_alloc() should not be called from interrupt context when the
KM_SLEEP flag is passed in. All other routines can be called from interrupt or kernel context.
SEE ALSO
kmem_alloc(9F)
Writing Device Drivers
SunOS 5.10 12 Dec 2001 id32_alloc(9F)