this code works on SGI does not work on linux 
Author Message
 this code works on SGI does not work on linux

here is a subroutine:

-----

/* Applies function func to a node if the result of comp is 0 *************/
/* Returns the logical sum of the results of the called functions *********/

int apply_tree(t,func,comp,args,dimension)

struct node_nD *t;
int (*func)();
int (*comp)();
void *args;
int dimension;

{
   int comp_result;
   int func_result;
   int iwk;

   if (t != NULL)
   {
      comp_result = comp(t->element,args,dimension);
      if (comp_result > 0)
         return(apply_tree((*t).left,func,comp,args,dimension));
      else if (comp_result < 0)
         return(apply_tree((*t).right,func,comp,args,dimension));
      else
      {
         func_result =  apply_tree((*t).left,func,comp,args,dimension);
         func_result |= apply_tree((*t).right,func,comp,args,dimension);
         if (t->next_dim == NULL)
            func_result |= func(t->element,args);
         else
            func_result |= apply_tree(t->next_dim,func,comp,args,++dimension);
         return(func_result);
      }  
   }
   else
   {
      return(0);
   }

Quote:
}

------

here is a subroutine which calls the previous one:

/***************************************************************************/
/* Reads points specified by  the flags from spectral region of arbitrary  */
/* size, position and orientation into a character array                   */
/* Input: handle for spectrum                                              */
/*        position within spectrum                                         */
/*        size of region to read                                           */
/*        orientation of sepctrum to read                                  */
/*        sizes of the destination array (must be smaller or equal than the*/
/*           size of the region to read                                    */
/*        array for storing intensities                                    */
/* Output: array of integer values                                         */
/* Side effects: resets file pointer and current_sub                       */
/***************************************************************************/

void
Read_Spec_Colors(param,pos,size,perm,dstsize,array)

Spec_Param_Data *param;   /* Data structure containing spectral parameters */
int pos[DIMENSION];       /* Position within spectrum                      */
int size[DIMENSION];     /* Groesse der Region                             */
int perm[DIMENSION];     /* Permutation Region                             */
int dstsize[DIMENSION];  /* destination size                               */
char array[];            /* Zu ladender Vektor                             */

{
   struct clip_data_nD clip;
   int i,j;
   int data_size;
   char *data_pntr;     /* Pointer into Array */
   float factor,offset;
   int newcolsize;
   int von,bis,set;

   if(param->file_type == FILE3D_8) {
      newcolsize = param->sub_size[param->permut[0]];
   } else {
      newcolsize = param->sub_size[param->permut[0]] * 2;
   }
   if(newcolsize > colsize) {
      if(colsize>0) free(col);
      colsize = newcolsize;
      col = (unsigned char *)malloc(sizeof(char) * colsize);
   }

/* Set clipping data ********************************************/

   for(i=param->dim;i<DIMENSION;i++)
   {
      size[i] = 1;
      dstsize[i] = 1;
      pos[i] = 0;
      perm[i] = i;
   }

   for(i=0;i<DIMENSION;i++)
   {
      clip.src.c[i] = pos[i];
      clip.src.s[i] = size[i];
      clip.dst.c[i] = 0;
      clip.dst.s[i] = dstsize[i];
      clip.dst_perm[i] = perm[i];
      clip.flags[i] = param->flags[i];
      von = pos[i]; if(von<0) von=0;
      bis = pos[i]+size[i]; if(bis>param->size[i]) bis = param->size[i];
      for(j=von;j<bis;j++) clip.flags[i][j] = 0;
      factor = (float)size[i] / (float)dstsize[i];
      offset = pos[i];
      for(j=0;j<dstsize[i];j++) {
         set = (int)((j + 0.4999) * factor + offset);
         if(set>=0 && set<bis)
            clip.flags[i][set] = 1;
      }
   }
   clip.data = &array[0];

/* Clear data for the case that not all data is available ******/
   data_size = 1;
   for(i=0;i<DIMENSION;i++) data_size *= clip.dst.s[i];
   for(data_pntr=array;data_pntr<array + data_size; data_pntr++)
                *data_pntr = 0;

/* Find and load matching submatrices **************************/

   spec_param = *param;
   rw_mode = READ_COLOR;
      for(i=1;i<=20;i=i+1){
   printf("array before %i \n", array[i]);}
   apply_tree(spec_param.subs,Clip_Copy_Data,
              Comp_Overlap_Left_nD,&clip,0);

      for(i=1;i<=20;i=i+1){
   printf("array after, %i\n", array[i]);}

Quote:
}

The main question is:

On SGI "array" (array after) after calling the apply_tree subroutine
is filled with integer number. On Linux "array" is filled with zeros
so subroutine does  not work the same way. The question for C masters
is what is possibly causing such problem in Linux.

Thank you in advance for all comments.

Witek



Mon, 31 May 2004 02:27:42 GMT  
 this code works on SGI does not work on linux
<snip 137 lines of pre-standard C code, for which gcc produces 96 lines of
 errors and warnings>

Quote:
>The main question is:

>On SGI "array" (array after) after calling the apply_tree subroutine
>is filled with integer number. On Linux "array" is filled with zeros
>so subroutine does  not work the same way. The question for C masters
>is what is possibly causing such problem in Linux.

I don't claim to be a C master, but I'll take a stab at it: the question
is not why the program doesn't do what you expect on Linux, it's why the
program even compiles (let alone does what you expect) on any platform.

I suggest that you create the smallest complete program which demonstrates
the problem. Turn your compiler's warning level up as far as possible, and
eliminate all warnings (unless you're absolutely certan that some of them
are superfluous). There's a good chance that in doing so you will find the
problem. If not, re-post your code and we'll have a look.

Also, note that old-style function definitions have been deprecated for
something like 12 years now. It's well past time to convert your code
to Standard C, especially if you are going to ask others to help you
with it.

I can't speak for other clc readers, but I'm considerably more willing to
spend a half hour debugging someone's code for free if they've put in a
minimum of effort to make it easier for me.

--
Server rooms should be unfriendly! They should look dangerous, they
should be uncomfortably cold, they should be inexplicably noisy. If
anything, I'd rather see rackmounted servers designed in dark foreboding
colors with lots of metal spikes sticking out of them. -- Mike Sphar in asr



Mon, 31 May 2004 16:41:26 GMT  
 this code works on SGI does not work on linux

Try commenting out your code until you spot the exact row that causes the
problem or post a tiny but working program demonstrating the problem so
that people can compile and run your code.  I do not spot any errors
causing the behaviour but then again, I do not see the whole code.

I have seen programs act like the way you describe when an array is being
declared too small.  Make sure that there is enough room in the `array'
when calling `Read_Spec_Colors'.

Toni Ronkko, University of Kuopio, Finland



Mon, 31 May 2004 18:29:12 GMT  
 this code works on SGI does not work on linux
witek,

well, it is hard to figure out what is the exact reason for this
mishap, though generally it should not happen. check the followings:
1: any difference between compilers on sgi and linux?
2: if you use the same gcc compiler, then start to check the compiling
errors on linux, since you ported sgi code over to linux. just turn
warning all on.
3: also if you use the same gcc compiler, then it must be the problem
on the way you port sgi code. make sure you have correct makefile on
linux.
4: it is not necessarily a problem on c.
5: assume that your new code is big, then it would be much easier for
you to get out everything else and just take the following code
snippet and put them into a dummy c program to see whether this dummy
program work or not. this is normally what i do when i port code from
one to another platform.
5: if 4 is working, then it confirms that you port it wrongly while 4
is not working, then i think we are in some fatal and hideous problem.

let me know how you find the solution.

cheers,

tony z.

Quote:

> here is a subroutine:

> -----

> /* Applies function func to a node if the result of comp is 0 *************/
> /* Returns the logical sum of the results of the called functions *********/

> int apply_tree(t,func,comp,args,dimension)

> struct node_nD *t;
> int (*func)();
> int (*comp)();
> void *args;
> int dimension;

> {
>    int comp_result;
>    int func_result;
>    int iwk;

>    if (t != NULL)
>    {
>       comp_result = comp(t->element,args,dimension);
>       if (comp_result > 0)
>          return(apply_tree((*t).left,func,comp,args,dimension));
>       else if (comp_result < 0)
>          return(apply_tree((*t).right,func,comp,args,dimension));
>       else
>       {
>          func_result =  apply_tree((*t).left,func,comp,args,dimension);
>          func_result |= apply_tree((*t).right,func,comp,args,dimension);
>          if (t->next_dim == NULL)
>             func_result |= func(t->element,args);
>          else
>             func_result |= apply_tree(t->next_dim,func,comp,args,++dimension);
>          return(func_result);
>       }  
>    }
>    else
>    {
>       return(0);
>    }
> }
> ------

> here is a subroutine which calls the previous one:

> /***************************************************************************/
> /* Reads points specified by  the flags from spectral region of arbitrary  */
> /* size, position and orientation into a character array                   */
> /* Input: handle for spectrum                                              */
> /*        position within spectrum                                         */
> /*        size of region to read                                           */
> /*        orientation of sepctrum to read                                  */
> /*   sizes of the destination array (must be smaller or equal than the*/
> /*      size of the region to read                                    */
> /*        array for storing intensities                                    */
> /* Output: array of integer values                                         */
> /* Side effects: resets file pointer and current_sub                       */
> /***************************************************************************/

> void
> Read_Spec_Colors(param,pos,size,perm,dstsize,array)

> Spec_Param_Data *param;   /* Data structure containing spectral parameters */
> int pos[DIMENSION];       /* Position within spectrum                      */
> int size[DIMENSION];     /* Groesse der Region                                */
> int perm[DIMENSION];        /* Permutation Region                             */
> int dstsize[DIMENSION];  /* destination size                               */
> char array[];               /* Zu ladender Vektor                             */

> {
>    struct clip_data_nD clip;
>    int i,j;
>    int data_size;
>    char *data_pntr;        /* Pointer into Array */
>    float factor,offset;
>    int newcolsize;
>    int von,bis,set;

>    if(param->file_type == FILE3D_8) {
>       newcolsize = param->sub_size[param->permut[0]];
>    } else {
>    newcolsize = param->sub_size[param->permut[0]] * 2;
>    }
>    if(newcolsize > colsize) {
>       if(colsize>0) free(col);
>       colsize = newcolsize;
>       col = (unsigned char *)malloc(sizeof(char) * colsize);
>    }

> /* Set clipping data ********************************************/

>    for(i=param->dim;i<DIMENSION;i++)
>    {
>       size[i] = 1;
>       dstsize[i] = 1;
>       pos[i] = 0;
>       perm[i] = i;
>    }

>    for(i=0;i<DIMENSION;i++)
>    {
>       clip.src.c[i] = pos[i];
>       clip.src.s[i] = size[i];
>       clip.dst.c[i] = 0;
>       clip.dst.s[i] = dstsize[i];
>       clip.dst_perm[i] = perm[i];
>       clip.flags[i] = param->flags[i];
>       von = pos[i]; if(von<0) von=0;
>       bis = pos[i]+size[i]; if(bis>param->size[i]) bis = param->size[i];
>       for(j=von;j<bis;j++) clip.flags[i][j] = 0;
>       factor = (float)size[i] / (float)dstsize[i];
>       offset = pos[i];
>       for(j=0;j<dstsize[i];j++) {
>          set = (int)((j + 0.4999) * factor + offset);
>          if(set>=0 && set<bis)
>             clip.flags[i][set] = 1;
>       }
>    }
>    clip.data = &array[0];

> /* Clear data for the case that not all data is available ******/
>    data_size = 1;
>    for(i=0;i<DIMENSION;i++) data_size *= clip.dst.s[i];
>    for(data_pntr=array;data_pntr<array + data_size; data_pntr++)
>            *data_pntr = 0;

> /* Find and load matching submatrices **************************/

>    spec_param = *param;
>    rw_mode = READ_COLOR;
>       for(i=1;i<=20;i=i+1){
>    printf("array before %i \n", array[i]);}
>    apply_tree(spec_param.subs,Clip_Copy_Data,
>               Comp_Overlap_Left_nD,&clip,0);

>       for(i=1;i<=20;i=i+1){
>    printf("array after, %i\n", array[i]);}

> }

> The main question is:

> On SGI "array" (array after) after calling the apply_tree subroutine
> is filled with integer number. On Linux "array" is filled with zeros
> so subroutine does  not work the same way. The question for C masters
> is what is possibly causing such problem in Linux.

> Thank you in advance for all comments.

> Witek



Wed, 02 Jun 2004 05:01:33 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. C++/ATL/ADO - Intellisense not working (statement completion options) not working

2. Works on unix, but not on Linux.....

3. Visual Basic DAO35 code OK but C++ code not working

4. CMap Lookup not working (at least I cannot get it to work)

5. Program not work at release mode but work at debug mode

6. GetPrivateProfileSectionNames not working in 98 or ME but does work in 2000

7. Window NT BitMap Works Windows95 BitMap Does not Work

8. GCC on SGI - does it work?

9. why does this code not work?

10. AtlReportError not working in ATL 7.0 (Injected code doesn't handle ErrorInfo properly)

11. why is this code(2) not working?

12. code from www.snippets.org - not working

 

 
Powered by phpBB® Forum Software