Note that there are some explanatory texts on larger screens.

plurals
  1. POmigration c++ code 32 bit machine to 64 bit machine
    primarykey
    data
    text
    <p>I am working on very legacy code which is migration to 32 bit to 64 bit machine.it generally write file with data which was working fine in 32 bit but having issue in 64 bit machine.When I check the file and found that it is generally contain division of 4 of 32 bit value. I mean if we have 80 value in 32 bit machine than it will be 20 in 64 bit machine.(most case). I have looked into below piece of code and could not understand some of functionality.</p> <ol> <li><p>why we call reverse function before write into File.</p></li> <li><p>What is purpose of reverse function.</p></li> <li><p>In write function,we always write one_ascii value although we have any data type.</p></li> </ol> <p>I have tried to took some piece of code which help me to explain issue briefly.Please let me know if I need to provide more information. </p> <pre><code>class GdsHeader { public: unsigned short rlen; char record_type; char data_type; }; class GdsRecord { public: #ifndef SWIG union { short *two_int; int *four_int; double *eight_real; char *one_ascii; // void *v; }; #endif int length; GdsRecord (); // { v = 0; length = 0; } ~GdsRecord () ;// { delete v; } void len (int l, int type); }; class GdsBlock { bool valid_block (); int len; public: bool record_unred; int header_ftell; GdsHeader h; GdsRecord r; int array_size; // bool re_read; // GdsBlock () { re_read = false; } GdsBlock () { record_unred = false; header_ftell = 0; } void set (int rt, int dt, int sz) {TBE; h.record_type = rt; h.data_type = dt; array_size = sz; r.len (sz, dt);TBX; } int read_header (FILE *); void read_block (FILE *); void write (FILE *); void prt (); }; void GdsRecord :: len (int l, int type) { switch (type) { case STREAM_Bit_array: case STREAM_Short: l *= 2; break; case STREAM_Long: l *= 4; break; case STREAM_Double: l *= 8; break; } if (l &gt; length) { l = ((l / 8) + 2) * 8; if (one_ascii) delete [] one_ascii; one_ascii = new char[l]; debug2.printf("GdsRecord::len new one_ascii len %d one_ascii %X\n",l, one_ascii); length = l; } } #ifndef sparc static void reverse (int len, char *buf) { TBE; char tmp[24]; int i; for (i = 0; i &lt; len; i++) tmp[i] = buf[i]; for (i = 0; i &lt; len; i++) buf[i] = tmp[ (len - 1) - i]; TBX; } inline void reverse (int len, short *s) { reverse (len, (char *) s); } inline void reverse (int len, int *s) { reverse (len, (char *) s); } inline void reverse (int len, double *s) { reverse (len, (char *) s); } inline void reverse (int len, unsigned char *s) {reverse (len, (char *) s); } #endif void GdsBlock :: write (FILE *outstr) { TBE; debug.printf("GdsBlock::write %X\n",outstr); int i, err; char *c, tmp; if (h.data_type == 3) { cout&lt;&lt;"Begin...blk.r.four_int[0] =&gt;"&lt;&lt;r.four_int[0]&lt;&lt;endl; } if (!this) error.printf_exit("GdsBlock::write error !this\n"); if (!outstr) error.printf_exit ("GdsBlock::write Error - outstr == 0\n"); err = ferror(outstr); cout&lt;&lt; __LINE__&lt;&lt;" "&lt;&lt;__PRETTY_FUNCTION__&lt;&lt;endl; if (err) { { char *s = strerror (err); fclose (outstr); error.printf_exit ("GdsBlock::write error - %s, errno %d\n", s, err); } switch(h.data_type) { case 0: /* NO DATA */ h.rlen = 4; cout&lt;&lt; __LINE__&lt;&lt;" "&lt;&lt;__PRETTY_FUNCTION__&lt;&lt;endl; break; case 1: /* BIT ARRAY */ cout&lt;&lt; __LINE__&lt;&lt;" "&lt;&lt;__PRETTY_FUNCTION__&lt;&lt;endl; #ifndef sparc reverse (2, &amp;r.two_int[0]); #endif h.rlen = (2 * array_size) + 4; break; case 2: /* TWO BYTE SIGNED INTEGER */ cout&lt;&lt; __LINE__&lt;&lt;" "&lt;&lt;__PRETTY_FUNCTION__&lt;&lt;endl; #ifndef sparc for (i = 0; i &lt; array_size; i++) reverse(2,&amp;r.two_int[i]); #endif h.rlen = (2 * array_size) + 4; break; case 3: /* FOUR BYTE SIGNED INTEGER */ cout&lt;&lt; __LINE__&lt;&lt;" "&lt;&lt;__PRETTY_FUNCTION__&lt;&lt;endl; #ifndef sparc for(i = 0; i &lt; array_size; i++) { cout&lt;&lt;r.four_int[i]&lt;&lt;endl; int *temp = &amp;r.four_int[i]; reverse(4,temp); //print_stacktrace(); cout&lt;&lt;r.four_int[i]&lt;&lt;endl; //r.four_int[i] = r.four_int[i] &lt;&lt; 2 ; } #endif h.rlen = (4 * array_size) + 4; break; case 5: /* EIGHT BYTE REAL */ cout&lt;&lt; __LINE__&lt;&lt;" "&lt;&lt;__PRETTY_FUNCTION__&lt;&lt;endl; #ifndef FPC for (i = 0; i &lt; array_size; i++) getr ((CONV *) (r.eight_real + i)); #endif #ifdef FPC for (i = 0; i &lt; array_size; i++) fpc (r.eight_real + i); #endif h.rlen = (8 * array_size) + 4; break; case 6: /* CHARACTER ARRAY */ cout&lt;&lt; __LINE__&lt;&lt;" "&lt;&lt;__PRETTY_FUNCTION__&lt;&lt;endl; h.rlen = array_size + 4; break; default: error.printf_exit("Error: bad record type %d in GdsBlock :: external\n", (int) h.data_type); } if (h.rlen % 2) { r.one_ascii[h.rlen] = 0; h.rlen++; } cout&lt;&lt; __LINE__&lt;&lt;" "&lt;&lt;__PRETTY_FUNCTION__&lt;&lt;endl; i = h.rlen - 4; #ifndef sparc c = (char *) &amp;h.rlen; tmp = c[0]; c[0] = c[1]; c[1] = tmp; #endif err = fwrite (&amp;h, 1, sizeof (h), outstr); if (err != sizeof(h)) { err = ferror(outstr); if (err) { char *s = strerror (err); fclose (outstr); error.printf_exit ("GdsBlock::write error - %s, errno %d\n", s, err); } fclose (outstr); error.printf_exit("Error: bad header fwrite in GdsBlock :: write\n"); } #if 1 err = fwrite (r.one_ascii, 1, i, outstr); if (err != i) { err = ferror(outstr); if (err) { char *s = strerror (err); fclose (outstr); error.printf_exit ("GdsBlock::write error - %s, errno %d\n", s, err); } fclose (outstr); error.printf_exit("Error: bad record fwrite in GdsBlock :: write\n"); } #endif debug.printf("GdsBlock::write exit\n"); TBX; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload