Click here to Skip to main content
15,898,134 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Thread Pin
CPallini12-Aug-09 3:28
mveCPallini12-Aug-09 3:28 
QuestionCWebBrowser - OnWindowClosingBrowser Method.. Pin
Member 383463011-Aug-09 23:44
Member 383463011-Aug-09 23:44 
AnswerRe: CWebBrowser - OnWindowClosingBrowser Method.. Pin
Bacon Ultimate Cheeseburger12-Aug-09 20:10
Bacon Ultimate Cheeseburger12-Aug-09 20:10 
GeneralRe: CWebBrowser - OnWindowClosingBrowser Method.. Pin
Member 383463012-Aug-09 22:29
Member 383463012-Aug-09 22:29 
GeneralRe: CWebBrowser - OnWindowClosingBrowser Method.. Pin
Bacon Ultimate Cheeseburger12-Aug-09 23:03
Bacon Ultimate Cheeseburger12-Aug-09 23:03 
QuestionQuestion on strict-aliasing Pin
Hing11-Aug-09 23:40
Hing11-Aug-09 23:40 
AnswerRe: Question on strict-aliasing Pin
Stuart Dootson12-Aug-09 6:14
professionalStuart Dootson12-Aug-09 6:14 
GeneralRe: Question on strict-aliasing [modified] Pin
Hing12-Aug-09 16:02
Hing12-Aug-09 16:02 
Thanks for your advice.

I do also think like that, GCC only implements the strict aliasing optimisation for variables of scalar types such as int, char, short, float etc. However, when I do an experiment below, it behaves the same as the (short*) and (long*) case (i.e. the content of the pointee is not changed):

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

typedef struct _MyStruct
{
	unsigned long a;
	unsigned long b;
}MyStruct;

typedef struct _MyStruct2
{
	unsigned short a;
	unsigned short b;
}MyStruct2;

int main()
{
	MyStruct a = {0x00010002, 0x00030004};
	MyStruct2* b = (MyStruct2*)(void*)&a;// = malloc(sizeof(unsigned short*));

	b->a = 5;
	b->b = 6;

//	b[1].a = 6;


	printf("hello world %x %x\r\n", (int)a.a, (int)a.b); // <-- 6 5
	return 0;
}


Really want to know the logic behind. Do anyone know the secret?

One more example here:

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

typedef struct _MyStruct
{
	unsigned char a;
	unsigned short b;
	unsigned long c;
	unsigned char d;

}MyStruct;

typedef struct _MyStruct2
{
	unsigned short a;
	unsigned char b;
}MyStruct2;

int main()
{
	MyStruct a = {0x01, 0x0002, 0x00000003, 0x04};
	MyStruct2* b = (MyStruct2*)&a;// = malloc(sizeof(unsigned short*));

	b->a = 5;
	b->b = 6;

//	b[1].a = 6;


	printf("hello world %x %x\r\n", (int)a.a, (int)a.b); // <-- 6 5
	return 0;
}


For the example above, the code will take effect (i.e. the content of the pointee is changed) no matter the strict-aliasing rule is on or off. There is even no type-puning warning apppear while compiling. Again, what is the logic behind?

BR,
Hing

modified on Thursday, August 13, 2009 2:34 AM

QuestionExamining a Message Queue Pin
ForNow11-Aug-09 22:53
ForNow11-Aug-09 22:53 
AnswerRe: Examining a Message Queue Pin
Stuart Dootson11-Aug-09 23:26
professionalStuart Dootson11-Aug-09 23:26 
QuestionVirtual Serial Port Question Pin
Programm3r11-Aug-09 22:24
Programm3r11-Aug-09 22:24 
AnswerRe: Virtual Serial Port Question Pin
Cedric Moonen11-Aug-09 23:01
Cedric Moonen11-Aug-09 23:01 
QuestionRe: Virtual Serial Port Question Pin
Programm3r11-Aug-09 23:27
Programm3r11-Aug-09 23:27 
AnswerRe: Virtual Serial Port Question Pin
Randor 12-Aug-09 9:31
professional Randor 12-Aug-09 9:31 
GeneralRe: Virtual Serial Port Question Pin
Programm3r12-Aug-09 20:01
Programm3r12-Aug-09 20:01 
Questionhow to display the IplImage into Picture control box. Pin
DevelopmentNoob11-Aug-09 22:13
DevelopmentNoob11-Aug-09 22:13 
AnswerRe: how to display the IplImage into Picture control box. Pin
zhu_lin11-Aug-09 22:59
zhu_lin11-Aug-09 22:59 
QuestionMaximum option to find a string/substring ,or compare option. Pin
Le@rner11-Aug-09 21:01
Le@rner11-Aug-09 21:01 
AnswerRe: Maximum option to find a string/substring ,or compare option. [modified] Pin
Adam Roderick J11-Aug-09 22:45
Adam Roderick J11-Aug-09 22:45 
AnswerRe: Maximum option to find a string/substring ,or compare option. Pin
zhu_lin11-Aug-09 23:10
zhu_lin11-Aug-09 23:10 
Questionload mp3 and seek by samples Pin
javad_200511-Aug-09 20:08
javad_200511-Aug-09 20:08 
AnswerRe: load mp3 and seek by samples Pin
zhu_lin11-Aug-09 23:12
zhu_lin11-Aug-09 23:12 
GeneralRe: load mp3 and seek by samples Pin
javad_200512-Aug-09 1:37
javad_200512-Aug-09 1:37 
GeneralRe: load mp3 and seek by samples Pin
zhu_lin12-Aug-09 2:55
zhu_lin12-Aug-09 2:55 
AnswerRe: load mp3 and seek by samples Pin
zhu_lin12-Aug-09 3:13
zhu_lin12-Aug-09 3:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.