NO

Author Topic: Prblem with struct  (Read 4089 times)

grom-it

  • Guest
Prblem with struct
« on: March 29, 2008, 06:32:33 pm »
Please help if poss
Pocke PC  App

struct
{
    wchar_t Location[40];     
        wchar_t Usize[30];
   wchar_t MakeUp[20];
   wchar_t GlassPattern[40];
   wchar_t GlassType[25];
   wchar_t SpacerColor[20];
    wchar_t Coating[30];     
   wchar_t GlassEffects[60];
      } unitsentered[50],unit,defaultunitpart;


Having assigned data to unit
i am having problems assigning
unitsentered[g_unitcount] with the data in unit

with this statement
 unitsentered[g_unitcount]=unit;

program compiles ok buts stops processing any statements in  the Function
after encountering the statement
unitsentered[g_unitcount]=unit

i am probably not assignining correctly.
I can give more info if needed

BTIA gromit

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2153
    • http://www.smorgasbordet.com
Re: Prblem with struct
« Reply #1 on: March 30, 2008, 03:18:00 pm »
Do you have some actual (compilable) code? You provide some details, but there is still too much guessing I think...
/Pelle

severach

  • Guest
Re: Prblem with struct
« Reply #2 on: March 30, 2008, 06:52:26 pm »
See if this works better. Something is wrong if it doesn't produce the exact same code.

Code: [Select]
memcpy(&unitsentered[g_unitcount],&unit,sizeof(unitsentered[g_unitcount])); //  unitsentered[g_unitcount]=unit;

grom-it

  • Guest
Re: Prblem with struct
« Reply #3 on: March 31, 2008, 09:44:57 pm »

Sorry Last Post very Muddled.


So made a small Pocket pc App
Selected simple program

Declared a  struct immediately below globals

struct
{
    wchar_t Location[40];     
        wchar_t Usize[30];
   wchar_t MakeUp[20];
   wchar_t GlassPattern[40];
   wchar_t GlassType[25];
   wchar_t SpacerColor[20];
    wchar_t Coating[30];     
   wchar_t GlassEffects[60];
      }unitsentered[10], emptyunitstruct,unit,defaultunitpart;
   
// Created this editbox in WM_CREATE and added IDC_TESTSTRUCT_EDITBOX to .h file

   //         CREATE AN EDIT BOX  FOR LISTVIEW
HWND hEdit;
     
 hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, L"EDIT", L"",
          WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_NOHIDESEL | ES_MULTILINE |

ES_READONLY,
    5,
        5,
        200,
        200, hwnd, (HMENU)IDC_TESTSTRUCT_EDITBOX, GetModuleHandle(NULL), NULL);
        if(hEdit == NULL)
            MessageBox(hwnd, L"Could not create edit box.", L"Error", MB_OK | MB_ICONERROR);
       
    return TRUE;



//added 1 menu item Testruct and placed an instruction in WM_COMMAND to run
      // FillStruct(hwnd) on menu selection

this results in that if either line 100 or 101 are left to compile
compiles ok but line 102 will not action
on the other hand if they are left out line 102 works???
see line nos below

static void FillStruct( HWND hwnd)

{
   wcscpy (unit.Location,L"Bed 1");
   wcscpy (unit.Usize ,L"111 x 222");
      wcscpy (unit.MakeUp,L"4/16/4");
   wcscpy (unit.GlassPattern,L"Cotswold");
   wcscpy (unit.GlassType,L"Silver");
    wcscpy (unit.Coating,L"Not Low E");     
    wcscpy (unit.GlassEffects,L"Georgian Fret");

wchar_t unitstring[150];
wcscpy (unitstring,L""); // set unitstring to null
 swprintf(unitstring,L"%s\r\n%s \t  %s\r\n%s\t%s\r\n%s\t%s\r\n%s\r\n __________________  \r\n",

unit.Location,

unit.Usize,unit.MakeUp,unit.GlassPattern,unit.GlassType,unit.SpacerColor,unit.Coating,unit.GlassE

ffects);
line 100
//memcpy(&unitsentered[1],&unit,sizeof(unitsentered[1])); //  unitsentered[g_unitcount]=unit;
 
line 101   //unitsentered[1]=unit;

line 102   SetDlgItemText(hwnd, IDC_TESTSTRUCT_EDITBOX, unitstring);   


}

Is it me or can i not assign structs in this fashion on a pocket pc

Big thanks for looking any help would be appreciated
gromit.

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2153
    • http://www.smorgasbordet.com
Re: Prblem with struct
« Reply #4 on: April 01, 2008, 12:16:21 am »
Both structure assignment and memcpy() will map to the same intrinsic code on ARM, which apparently have problems with alignment. Try this hack to force the use of the memcpy *function* until I have more time to look at this... (may take a little while...)

Code: [Select]
void * (*__cdecl memcopy)(void * restrict, const void * restrict, size_t) = memcpy;
(*memcopy)(&unitsentered[1], &unit, sizeof(unitsentered[1]));
/Pelle

grom-it

  • Guest
Re: Prblem with struct
« Reply #5 on: April 01, 2008, 10:13:04 pm »

 :) :D ;D

Thanks for the hack Pelles It worked fine

I am just pleased that i know whats what
A workround was always a possibility
Yours a bit more sophisticated than that i would have come up with

Once again thankyou for your help and patience

May I take this opportunity to thank you for the hours of enjoyment i have had learning C whilst using Pelles C
Big Thanks ...
gromit
 

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2153
    • http://www.smorgasbordet.com
Re: Prblem with struct
« Reply #6 on: April 04, 2008, 05:01:48 pm »
OK, good that it worked out (for now) - and thank you...!

/Pelle