Click here to Skip to main content
15,918,596 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Doubleclick on MDI Frame Pin
Stuart Dootson12-Aug-09 6:32
professionalStuart Dootson12-Aug-09 6:32 
QuestionInstalling a driver and Registry settings!! Pin
kapardhi12-Aug-09 0:56
kapardhi12-Aug-09 0:56 
AnswerRe: Installing a driver and Registry settings!! Pin
Randor 12-Aug-09 9:08
professional Randor 12-Aug-09 9:08 
QuestionThread Pin
susanne111-Aug-09 23:46
susanne111-Aug-09 23:46 
AnswerRe: Thread Pin
CPallini12-Aug-09 0:07
mveCPallini12-Aug-09 0:07 
GeneralRe: Thread Pin
susanne112-Aug-09 0:09
susanne112-Aug-09 0:09 
AnswerRe: Thread Pin
CPallini12-Aug-09 0:13
mveCPallini12-Aug-09 0:13 
GeneralRe: Thread Pin
susanne112-Aug-09 0:15
susanne112-Aug-09 0:15 
GeneralRe: Thread Pin
CPallini12-Aug-09 0:56
mveCPallini12-Aug-09 0:56 
AnswerRe: Thread Pin
Rajesh R Subramanian12-Aug-09 0:25
professionalRajesh R Subramanian12-Aug-09 0:25 
GeneralRe: Thread Pin
susanne112-Aug-09 0:27
susanne112-Aug-09 0:27 
GeneralRe: Thread Pin
Rajesh R Subramanian12-Aug-09 1:23
professionalRajesh R Subramanian12-Aug-09 1:23 
GeneralRe: Thread Pin
CPallini12-Aug-09 1:51
mveCPallini12-Aug-09 1:51 
GeneralRe: Thread Pin
Rajesh R Subramanian12-Aug-09 2:08
professionalRajesh R Subramanian12-Aug-09 2:08 
GeneralRe: Thread Pin
CPallini12-Aug-09 2:38
mveCPallini12-Aug-09 2:38 
GeneralRe: Thread Pin
Rajesh R Subramanian12-Aug-09 2:45
professionalRajesh R Subramanian12-Aug-09 2:45 
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 

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.