Re[2]: [cc65] preprocessor hazzle...

Date view Thread view Subject view

From: groepaz (groepaz_at_gmx.net)
Date: 2002-07-30 04:28:10


Hello Ullrich,

Monday, July 29, 2002, 8:20:01 AM, you wrote:

UvB> Hi!

UvB> On Fri, Jul 26, 2002 at 11:56:51PM +0200, groepaz wrote:
>> coolio :o) btw, i guess i can safely assume that the snapshots you
>> generate each nite (i guess? looks like it atleast ;=P) always have
>> all those patches applied?

UvB> Unfortunately not .There are situations where the development sources are in a
UvB> state that does not allow to apply the patch, or sometimes I choose a
UvB> different solution for the development sources.

uhoh..... ok, i understand ;=P

UvB> Works here. The only thing that does not work is something like this:

UvB>         int bar;

UvB>         void foo (void)
UvB>         {
UvB>             extern int bar;
UvB>         }
                          
UvB> So as long as you don't have both, a declaration and an extern definition in
UvB> your sources, they should be ok.

well yes, its (ofcoz) like you say :o) there are global variables
defined all over the source and then they are declared as extern in
every function that uses them. (just as a sidenote, what benefit is
expected from this way of declaring things? (instead of simply
referring to the globals?) seen that in a couple of sources already,
the testsuite for example uses this extensivly)

>> and then "bla" is somewhere reused in an expression where the size of
>> "bla" must be known..... resulting in an "size of "bla" unknown"
>> error. i am not sure here, but afaik "bla[]" equals "*bla" in an
>> expression and thus its size (the size of the pointer) _is_ known and
>> such an error shouldnt occur. (ok i could come up with a testprog
>> aswell here but maybe you know where to look already :o))

UvB> If the size of bla[] is the size of a pointer, what would you expect from
UvB> sizeof(bla[3])? I don't know about the code you're testing, but gcc does not
UvB> accept this construct either:

UvB>         t.c:6: sizeof applied to an incomplete type

oh yes, you are right.... my attempt on explaining what was going
wrong probably didnt turn out to well :o)

i have knocked up a testprog that shows the problem more exactly (and
another problem aswell).... attached at the bottom of this mail :)

>> btw! i tried compiling with an oldish mingw32 install aswell (cygwin
>> compiled binaries are kinda sloooooooow ;=P) and noticed that
>> somewhere the code relies on fork() and friends and maybe some other
>> things used to spawn a sub-process in *nix.... is there a way to
>> compile the source for a target that has simple "spawn..." functions
>> but no fork() already?

UvB> The Windows version uses spawn() from it's own library. The unix version has
UvB> an additional module that implements spawn().

oh! have to look closer again then....

-- 
Best regards,
 groepaz                            mailto:groepaz_at_gmx.net


------ testprog

#include <stdio.h>

/*
  check behaviour on incompletely declared arrays
*/

#ifndef __CC65__
// cc65: Error: Variable `i1' has unknown size
char i1[];
#endif

void test1(void) {
int a;

//int bla[];
//gcc: array size missing in "bla"
//      a=sizeof(bla);
//      printf("%04x\n",a);
//gcc: array size missing in "bla"
//      a=sizeof(bla[0]);
//      printf("%04x\n",a);

//gcc:  sizeof applied to an incomplete type
//      a=sizeof(i1);
//      printf("%04x\n",a);

#ifndef __CC65__ // cc65 dont compile this
//gcc: warning: array `i1' assumed to have one element
//
// this is probably undefined behavior ?
//
        a=sizeof(i1[0]);
        printf("%04x - ",a);
        if(sizeof(i1[0])==sizeof(char)) {
                // gcc gives size of element
                printf("sizeof(i1[0]) gives size of element\n");
        }
        if(sizeof(i1[0])==sizeof(char*)) {
                printf("sizeof(i1[0]) gives size of pointer to element\n");
        }
#endif

}

/*
  check behaviour on string init
*/

char t1[]="abcde";
// cc65 Warning: Converting pointer to integer without a cast
// (?! eh ?!)
char t2[]={"abcde"};

#ifndef __CC65__
// cc65 Error: Expression expected
char *t3="abcde";
// cc65 Error: Expression expected
char *t4={"abcde"};
#else
// just to make it compile, the test will fail anyway ;=P
char t3[]=".....";
char t4[]=".....";
#endif

void test2(void) {
char c1,c2,c3,c4;
int i,e=0;
        for(i=0;i<5;i++){
                c1=t1[i];c2=t2[i];c3=t3[i];c4=t4[i];
                printf("%02x %02x %02x %02x\n",c1,c2,c3,c4);
                if(!((c1==c2)&(c1==c3)&(c1==c4))) e=1;
        }
        if(e) printf("test2 failed.\n");
        else printf("test2 ok.\n");
}

/*
  check behaviour on extern-declarations inside functions
*/

typedef struct {
  char *name;
  void *func;
} A3;

#ifdef __CC65__

A3 a3[] = {
  { "test3", (void*) NULL },
  { "test3", (void*) NULL },
};

#else
//gcc warning: missing braces around initializer (near initialization for `a3[0]')
// this type of struct-initialization seems to be kinda common so
// causes lotta stuff to not compile with cc65 ;/
A3 a3[] = {
    "test3", (void*) NULL  ,
    "test3", (void*) NULL  ,
};
#endif

void test3a(A3 *list, int number){
        printf("%s %d\n",list->name,number);
}

// original variation, works ok with gcc
#if 0
static void test3(void)
{
        // cc65:  Error: Variable `a3' has unknown size
    extern A3 a3[];
    test3a(a3, -1);
}
#endif

#if 0
// this variation compiles with cc65 if test3()
// is not called from main()...probably also if a3 would be REALLY extern
static void test3(void)
{
        // cc65: Error #41: Symbol `_a3' is already defined
    extern A3 *a3;
    test3a(a3, -1);
}
#endif

#if 1
// this works with cc65
static void test3(void)
{
    test3a(a3, -1);
}
#endif

/*
  todo: add test on function pointers in the form of (*func)(arg) ...
  cc65 seems to have problems here aswell ;/
*/

int main(void) {

        test1();
        test2();
    test3();

    /* return OK */
    return(0);

}


----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo_at_musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.


Date view Thread view Subject view

This archive was generated by hypermail 2.1.3 : 2002-07-30 04:29:40 CEST