473,473 Members | 2,357 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Re: Memory allignment/type casting question

#include <stdlib.h>
#include <stdio.h>

int main (int argc, char*argv[])
{
unsigned char c[] = {0,1,2,3,4,5,6,7,8,9,10};
unsigned int *i1, *i2, *i3;
i1 = (unsigned int *)&c[0];
i2 = (unsigned int *)&c[1];
i3 = (unsigned int *)&c[2];
printf("0x%06x 0x%06x 0x%06x",i1,i2,i3);

system("PAUSE");
return 0;
}
Oct 8 '08 #1
1 2094
ba**********@gmail.com wrote:
#include <stdlib.h>
#include <stdio.h>

int main (int argc, char*argv[])
{
unsigned char c[] = {0,1,2,3,4,5,6,7,8,9,10};
unsigned int *i1, *i2, *i3;
i1 = (unsigned int *)&c[0];
i2 = (unsigned int *)&c[1];
i3 = (unsigned int *)&c[2];
printf("0x%06x 0x%06x 0x%06x",i1,i2,i3);

system("PAUSE");
That is a gratuitously unportable piece of code. 'PAUSE' might not even
be supported by system() on the OP's machine; it's not supported on any
machine I program on. Even if it is supported, it might not do what you
expect it to do.
return 0;
}
Oct 8 '08 #2

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

Similar topics

2
by: Patchwork | last post by:
Hi Everyone, I have a design-/implementation-related question for you all. In practical usage of C++, especially when processing image or audio data with 3rd party libraries, there often...
4
by: C++fan | last post by:
Hi all: I have a question about memory allocation to an object of a class. For example, I define the following class: class example_class{ public: example_class(); void funtion_1();
11
by: Roman Hartmann | last post by:
hello, I do have a question regarding structs. I have a struct (profil) which has a pointer to another struct (point). The struct profil stores the coordinates of points. The problem is that I...
11
by: William Buch | last post by:
I have a strange problem. The code isn't written by me, but uses the qsort function in stdlib. ALWAYS, the fourth time through, the memory location of variable list (i.e. mem location = 41813698)...
72
by: ravi | last post by:
I have a situation where i want to free the memory pointed by a pointer, only if it is not freed already. Is there a way to know whether the memory is freed or not?
10
by: s.subbarayan | last post by:
Dear all, I happen to come across this exciting inspiring article regarding memory leaks in this website: http://www.embedded.com/story/OEG20020222S0026 In this article the author mentions:...
26
by: Bill Reid | last post by:
Bear with me, as I am not a "professional" programmer, but I was working on part of program that reads parts of four text files into a buffer which I re-allocate the size as I read each file. I...
12
by: FI | last post by:
Hello All, I am relatively new to C programming and I am struck with a problem in dynamic memory allocation. I would like to know if it is ok to pass the 'memory address' returned by...
171
by: Raman | last post by:
Hi All, Here is a small Code, int main(void) { char *p=(char *) malloc(100); strcpy(p,"Test1234567890"); p=p+10; free(p);
5
by: Mahendra Kumar Kutare | last post by:
I am trying to implement a webserver with boss-worker model thread pool implementation - I have a header declaration threadpool.h as - typedef struct threadpool_work { void (*routine) ();...
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
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...
1
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,...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.