[comp.windows.ms.programmer] -Zp Option Problem

rluzzi@dit.upm.es (Roman Roberto Luzzi) (05/22/91)

Hello:

  I have problems with the package option -Zp of the Microsoft C 6.0 
Compiler when I pass structures to functions as value parameters.
When the structures have odd size, in the calling to the function 
the compiler puts in the stack the structure correctly (with odd size), 
but the compiler defines the target function parameters with even size 
(it doesn't pack the parameters in byte boundaries).
The simple code below is an example of the problem:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

struct OddName {
        unsigned int present;
	char value[9];
	} n1, n2, n3;

static void 
teststack(struct OddName nx, struct OddName ny, struct OddName nz);

static void
teststack(struct OddName nx, struct OddName ny, struct OddName nz)
{
 printf("STACK TEST Init...\n");
 printf("Value 1 Received %s\n",nx.value);
 printf("Value 2 Received %s\n",ny.value);
 printf("Value 3 Received %s\n",nz.value);
 printf("STACK TEST Finish.\n");
}

void main ()
{
 strcpy(n1.value,"1234");
 strcpy(n2.value,"1234");
 strcpy(n3.value,"1234");
 teststack(n1, n2 ,n3);
 exit(0);
}

This simple program was compiled with:  CL -AS -Zp -W4 test.c
and its output was:
  STACK TEST Init...
  Value 1 Received 1234
  Value 2 Received 234
  Value 3 Received 34
  STACK TEST Finish.


As you can see, the function parameters have a size of 12 bytes (-Zp doesn't 
work!!), and the variables have a size of 11 bytes (correct -Zp package).
Obviously, this same program works correctly without the -Zp option, but 
it is necessary in Windows environment.

Has anyone had this problem prior? Thanks in advance.

		       Roman Luzzi.(rluzzi@dit.upm.es)

richardb@cognos.UUCP (Richard Brosseau) (05/24/91)

In article <RLUZZI.91May22123346@greco.dit.upm.es> rluzzi@dit.upm.es (Roman Roberto Luzzi) writes:
+
+
+
+Hello:
+
+  I have problems with the package option -Zp of the Microsoft C 6.0 
+Compiler when I pass structures to functions as value parameters.
+When the structures have odd size, in the calling to the function 
+the compiler puts in the stack the structure correctly (with odd size), 
+but the compiler defines the target function parameters with even size 
+(it doesn't pack the parameters in byte boundaries).
+The simple code below is an example of the problem:

[Code deleted]

+Has anyone had this problem prior? Thanks in advance.
+
+		       Roman Luzzi.(rluzzi@dit.upm.es)

Yes, I've had this problem. It appears to be a C600 compiler bug.

A solution would be to pad the structure to an even number of bytes
or just pass a pointer to the struct instead.

-- 
Richard Brosseau       ccs.carleton.ca!cognos.uucp!richardb

I think a burp died trying to get out of my mouth - Calvin

Gary_Capps@p27.f30.n147.z1.fidonet.org (Gary Capps) (05/30/91)

In a message of <23 May 91 20:11:27> Richard Brosseau wrote to All:

 RB>+  I have problems with the package option -Zp of the Microsoft C 6.0
 RB>
 RB>+Compiler when I pass structures to functions as value parameters.
 RB>+When the structures have odd size, in the calling to the function 
 RB>+the compiler puts in the stack the structure correctly (with odd size),
 RB>
 RB>Yes, I've had this problem. It appears to be a C600 compiler bug.

This, I believe was fixed in 6.0a

gc