Re: __unaligned before and after the * (64bit)



On Mar 19, 11:18 pm, Ulrich Eckhardt <dooms...@xxxxxxxx> wrote:
Udiwrote:
I'm not sure I understand the difference between placing the
__unaligned before or after the *:

I guess, it works like 'const', which applies to the left unless it is at
the leftmost side, then it applies to the right. However, it is, as others
pointed out, non-standard, so you have to consult the compiler docs.

I was trying to handle the C4366 warning - "The result of the unary
'&' operator may be unaligned") and used the '__unaligned' modifier as
suggested, but ended up with C4090 - "different '__unaligned' qualifiers".
(See below)
However, moving the __unaligned keyword after the ' * '
solved the warning but I'm not sure I solved the probelm.

I don't think so...



void List_Clear(List *pList) ;
:
List  * pSubscribersList = NULL;

pSubscribersList = (List *)&(p->subscribersList); //C4366: The result
of the unary '&' operator may be unaligned

Well, the first problem here is that you are using casts, which is typically
a sign that something's wrong. Remove those, and you won't need any
unaligned attributes. If it doesn't compile then, your types simply don't
match, but adding them doesn't change that. If you can't do it yourself or
want to verify the solution is correct, please boil your problem down to a
minimal but complete example, in particular guessing
what 'p->subscribersList' could be is pretty hart.

Uli

Thanks All,
I agree I shouldn't use the __unaligned, that's why I'm writing to
figure out how.

Here are the full types and example:

typedef struct
{
HANDLE hAccess; // Mutex
HANDLE hCanRead; // Event
HANDLE hCanWrite; // Event
HANDLE hWriterMutex; // Mutex
DWORD dwTlsSlot;

DWORD dwTotalReaderThreads;
DWORD dwTotalWriterThreads;
} tReadWriteLock;

typedef struct _ListItem
{
void *pData;
struct _ListItem *pNextItem;
} ListItem;

typedef struct
{
ListItem *pHead;
DWORD dwLength;
tReadWriteLock *pLock;
} List;

typedef struct
{
DWORD id;
List subscribersList;
} IndicatorSubscribers;


with no __unaligned keyword --> Warning C4366
```````````````````````````````````````````````````````````````````````
void List_Clear(List *pList) ;
:
List * pSubscribersList = NULL;


pSubscribersList = (List *)&(p->subscribersList); //C4366: The result
of the unary '&' operator may be unaligned
List_Clear(pSubscribersList);


__unaligned before the * --> warning C4090
```````````````````````````````````````````````````````````````
void List_Clear(List *pList) ;
:
List __unaligned * pSubscribersList = NULL;


pSubscribersList = (List __unaligned *)&(p->subscribersList);
List_Clear(pSubscribersList); //warning C4090: 'function' : different
'__unaligned' qualifiers


__unaligned after the * --> no warnings
````````````````````````````````````````````````````````
void List_Clear(List *pList) ;
:
List * __unaligned pSubscribersList = NULL;


pSubscribersList = (List * __unaligned)&(p->subscribersList);
List_Clear(pSubscribersList); // OK - no warning




As you can see these are all pretty simple typedefs.
So the 'p' in 'p->subscribersList' is of type 'IndicatorSubscribers'.

Any ideas now?
(Still I didn't get the difference between placing the __unaligned
before and after the *.)

Thanks,
Udi


.



Relevant Pages

  • struct with variable length member
    ... struct AAA with a3 as a DWORD? ... void main{ ...
    (microsoft.public.vc.language)
  • Re: WaitCommEvent?
    ... void ShowLastError; // detailed err displaying ... DWORD Connect; ... virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam); ... CString row = display.GetRow; ...
    (microsoft.public.pocketpc.developer)
  • Re: The Tcl notifier and Console on Windows
    ... void FileIORead; ... DWORD PostOverlappedRead; ... // Get our input stream (con or pipe). ... // Create our alert event ...
    (comp.lang.tcl)
  • Writing a service...
    ... the time zone and forces a resync with a time server on initialisation. ... void ServiceMain; ... int InitService; ... int UpdateSCMStatus (DWORD dwCurrentState, DWORD dwWin32ExitCode, ...
    (comp.lang.c)
  • Re: aygshell.h
    ... Include AYGSHELL in your catalog items in Platformbuilder, ... typedef struct tagSHMENUBARINFO ... DWORD cbSize; ... UINT fSipOnDeactivation:1; ...
    (microsoft.public.windowsce.platbuilder)