Click here to Skip to main content
16,005,048 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: HELP PLEASE!!! CRAZY COMPILERS????? Pin
tguzella19-Oct-03 12:45
tguzella19-Oct-03 12:45 
AnswerRe: HELP PLEASE!!! CRAZY COMPILERS????? Pin
markkuk19-Oct-03 22:48
markkuk19-Oct-03 22:48 
AnswerRe: HELP PLEASE!!! CRAZY COMPILERS????? Pin
jhwurmbach19-Oct-03 22:56
jhwurmbach19-Oct-03 22:56 
GeneralMacro accessing a function from another macro file Pin
Jeff Miles19-Oct-03 12:35
Jeff Miles19-Oct-03 12:35 
GeneralDatabase connection through MFC help Pin
Mike Danberg19-Oct-03 12:33
Mike Danberg19-Oct-03 12:33 
GeneralRe: Database connection through MFC help Pin
Michael P Butler19-Oct-03 23:35
Michael P Butler19-Oct-03 23:35 
GeneralRe: Database connection through MFC help Pin
Mike Danberg20-Oct-03 6:16
Mike Danberg20-Oct-03 6:16 
GeneralHelp with some C Pin
Sirrius19-Oct-03 11:05
Sirrius19-Oct-03 11:05 
I have some C code here, my teachers, that I'm trying to rifle through and figure out. I am confused on on line of it: The second line down is

*b = (int*) malloc ( n * sizeof(int)); 


does this mean a integer pointer that point to a memory location that is 4 times the size of an integer? Which would be then 16 bytes. So a int pointer that points to 16 bytes of vacant memory. Am I right, close or way off.

Please help. the code below is what it is out of.

Thanks for your help.


#include "stdio.h"

void ByteSwap4_c(int n, int *a);
void ByteSwap4_asm(int n, int *a);

void ByteSwap4(int n, int *a)
{
  int i;
  int *b = (int*) malloc ( n * sizeof(int));
  for (i=0; i<n; ++i) 
	  b[i]=a[i];

  ByteSwap4_asm(n,a);
  ByteSwap4_c(n,b);

  for (i=0; i<n; ++i) 
  {
    if (a[i] != b[i]) 
	{
      printf("a[%d] (0x%08X) != b[%d] (0x%08X)\n",i,a[i],i,b[i]);
      exit(1);
    }
  }

  free(b);
}

void test4(int n, int *a, int *b)
{
  int i;
  ByteSwap4(n,a);
  for (i=0; i<n; ++i) {
    if (a[i] != b[i]) {
      printf("a[%d] (0x%08X) != b[%d] (0x%08X)\n",i,a[i],i,b[i]);
      exit(1);
    }
  }
}

int main()
{
  static int a[4]={0x01020304, 0xa0b0c0d0, 0xabdcef12, 0x12345678};
  static int b[4]={0x04030201, 0xd0c0b0a0, 0x12efdcab, 0x78563412};

  test4(4,a,b);

  printf("all tests pass\n");
}





void ByteSwap4_c(int n, int *a)
{
  int i;
  for (i=0; i<n; ++i) 
  {
    /* byte swap a[i] */
    int tmp=a[i];
    int pmt;
    ((char*)(&pmt))[3]=((char*)(&tmp))[0];
    ((char*)(&pmt))[2]=((char*)(&tmp))[1]; 
    ((char*)(&pmt))[1]=((char*)(&tmp))[2];
    ((char*)(&pmt))[0]=((char*)(&tmp))[3];

    a[i]=pmt;
  }
}

GeneralRe: Help with some C Pin
markkuk19-Oct-03 11:45
markkuk19-Oct-03 11:45 
GeneralRe: Convert int to hexa Pin
Alexander M.,19-Oct-03 10:26
Alexander M.,19-Oct-03 10:26 
GeneralRe: MRU problem Pin
Neville Franks19-Oct-03 9:45
Neville Franks19-Oct-03 9:45 
GeneralRe: MRU problem Pin
YaronNir19-Oct-03 22:47
YaronNir19-Oct-03 22:47 
GeneralRe: MRU problem Pin
Neville Franks19-Oct-03 23:13
Neville Franks19-Oct-03 23:13 
GeneralRe: MRU problem Pin
YaronNir19-Oct-03 23:25
YaronNir19-Oct-03 23:25 
GeneralRe: MRU problem Pin
Neville Franks20-Oct-03 0:02
Neville Franks20-Oct-03 0:02 
GeneralRe: MRU problem Pin
YaronNir20-Oct-03 0:14
YaronNir20-Oct-03 0:14 
GeneralRe: MRU problem Pin
Neville Franks20-Oct-03 2:16
Neville Franks20-Oct-03 2:16 
GeneralRe: MRU problem Pin
YaronNir20-Oct-03 2:41
YaronNir20-Oct-03 2:41 
GeneralRe: MRU problem Pin
Neville Franks20-Oct-03 21:16
Neville Franks20-Oct-03 21:16 
GeneralApplication does not terminating Pin
csperber19-Oct-03 7:42
csperber19-Oct-03 7:42 
GeneralRe: Application does not terminating Pin
Neville Franks19-Oct-03 9:47
Neville Franks19-Oct-03 9:47 
GeneralRe: Application does not terminating Pin
csperber20-Oct-03 8:30
csperber20-Oct-03 8:30 
GeneralRe: Application does not terminating Pin
Anthony_Yio20-Oct-03 1:42
Anthony_Yio20-Oct-03 1:42 
GeneralRe: Application does not terminating Pin
csperber20-Oct-03 8:39
csperber20-Oct-03 8:39 
GeneralRe: Application does not terminating Pin
Anthony_Yio20-Oct-03 16:19
Anthony_Yio20-Oct-03 16:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.