Jump to content

Pointer Comparison And Assignment

Recommended Posts

Dave / Pavel,


I have found another odd quirk. Nearest message I can find to this problem, which may be related, is: "Cannot Compare Pointers" posted on Feb 10 2006 in this forum.


I have a working fix for the problem, which I've annotated for your easy testing using the macro FIX_LEVEL , and I would appreciate your comments.


Problem 1. Comparison of two pointers of the same type fails. See macro BOOSTC_CAST_PTRS

Problem 2. Assignment of the pointer to another pointer of the same type fails. See macro BOOSTC_FIX_ASSIGN


struct stST {
 struct stST * pNext; // -> Next ST
 int x;
 int y;
 int z;
 // Other stuff i.e.

struct stQ {
 unsigned char Count;
 struct stST * pST;

struct stST   CurrST;
struct stST * pCurrST=&CurrST;

struct stQ   Qone;
struct stQ * pQone=&Qone;

struct stQ   Qtwo  ;
struct stQ * pQtwo=&Qtwo;

void MoveQs(struct stST *pThisST, struct stQ *pFromQ, struct stQ *pToQ);

// FIX_LEVEL ---- this is for easier testing of what works
//   == 0 no fix
//   == 1 cast for ptr comparison
//   == 2 working cast for ptr comparison
//   == 3 working solution
#define FIX_LEVEL  0

#pragma message "FIX_LEVEL is = " FIX_LEVEL
#if FIX_LEVEL == 0
#elif FIX_LEVEL == 1  
 #define BOOSTC_CAST_PTRS (struct stST *)
#elif FIX_LEVEL == 2  
  #define BOOSTC_CAST_PTRS (void *)
#elif FIX_LEVEL == 3  
 #define BOOSTC_CAST_PTRS (void *)
 #define BOOSTC_FIX_ASSIGN (struct stST*)
 #pragma message "FIX_LEVEL must be in range 0 - 3, it is = " FIX_LEVEL
 #error  "Aborted compilation"

void main() 
 pCurrST->pNext=pCurrST; // point to self


void MoveQs(struct stST * pThisST, struct stQ * pFromQ, struct stQ * pToQ)
 struct stST * pChk;
 struct stST * pLast;  
 struct stST * pFirst;
 if(pFromQ->Count) {
   if(pFromQ->Count==1) {
     // only one ST on the Q
     pFromQ->pST=(struct stST *)0;
     // First ST on the Q
     pFromQ->pST=BOOSTC_FIX_ASSIGN pThisST->pNext;
     // Follow the Q to the ST
     pLast->pNext=BOOSTC_FIX_ASSIGN pThisST->pNext;
   // ST has now been removed from the FromQ
   // Now add it to the ToQ
   if(pToQ->Count) {
     // find the end of the ToQ
     do {
     } while(BOOSTC_CAST_PTRS pChk!=BOOSTC_CAST_PTRS pFirst);      
   else {
     // ToQ is currently empty

Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...