Re: Need help to port VAX code to Alpha and to Itaninum

From: John E. Malmberg (wb8tyw_at_qsl.network)
Date: 03/22/05


Date: Tue, 22 Mar 2005 08:40:21 -0500

Laksh wrote:
> Hi guys,
> I am working on project, which involves porting kind of stuff from VAX
> code Alpha and to Itaninum. Here what I am working project very big and
> vast of codeing files are there. I have compiled with our old vax code
> /stand=relaxed_ansi instead of /stand=vaxc. I hope that What I am doing
> rt :). But thing is while compile with option I got so many warning
> errors like as show below. This is a bit of code
>
> #include <stdio.h>
> int main(){
> unsigned long int GEN_TRANS_LOGICAL(char *, char *);
> char as_logical[] = "DECEDI$AS_PERF";
> char as_text[257] = {0};
> as_logical_status = GEN_TRANS_LOGICAL( &as_logical, &as_text);
> }
>
> 1st case: If I compile with /stand=Vaxc, I didn't get any of warning
> messages.

/VAXC puts the compiler in a mode where it will ignore many critical
errors that past C specifications did not require checks for.

/VAXC should be removed from any program in development that you care
about getting correct answers from.

I would recommend instead to use /WARN=ENABLE=(LEVEL4, QUESTCODE)

Some of the informational diagnostics that this generates can be
ignored, but others will find critical programming errors.

> 2nd case: If I compile with /stand=relaxed_ansi, it came up with lot of
> warning errors like as shown below.
>
> CC
> /OBJ=REFTEST/NOLIST/NODEBUG/NOANA/NOOPTIMIZE=(INLINE=AUTO,LEVEL=4,UNROLL=0)/Incl=DECEDI_SRC:/DEFIN=MEMBER_ALIGN/WARN
> =(NOINF,DISABLE=PROTOSCOPE3,ENABLE=ALIGNMENT)/FLOAT=IEEE reFTEST.C
>
>
> as_logical_status = GEN_TRANS_LOGICAL(&as_logical,&as_text);
> ..............................................^
> %CC-W-PTRMISMATCH, In this statement, the referenced type of the
> pointer value "&as_logical" is "array [7] of char", which is not co
> mpatible with "char".
> at line number 8 in file EDIV43:[WRK]REFTEST.C;11
>
> as_logical_status = GEN_TRANS_LOGICAL(&as_logical,&as_text);
> ..........................................................^
> %CC-W-PTRMISMATCH, In this statement, the referenced type of the
> pointer value "&as_text" is "array [257] of char", which is not com
> patible with "char".
> at line number 8 in file EDIV43:[WRK]REFTEST.C;11
>
> If I remove '&' from the line "as_logical_status = GEN_TRANS_LOGICAL(
> &as_logical, &as_text); ", that error went off.

> Can anybody helps me why is coming like this? How to rectify this
> problem , without changing code in almost in every place around 7000
> places.. Is there any way to rectify this?.

Not really, the original code was wrong, and the compiler was not
diagnosing the problem. It also appears to be a common coding error in
older C programs.

Some of the editors allow you to write macro programs in them so that
you can use those macros to automatically make many similar corrections.

Arrays are passed by address on C. When you explicitly add an & to
them, you are passing the address of the array variable instead of a
pointer to the start of the array.

So you are trying to pass a pointer to a pointer to an array where you
have told the compiler only passing a pointer to the array.

In the case of an array declared the way that you have done the two
above, both values end up the same even though the types do not match.

In other cases though, if you are working with pointer variables, the
resulting value is totally different, and will likely cause data
corruption, as instead of passing the intended array, the usual result
is passing a pointer to the local stack.

> I used Compaq C v6.5 compiler.
> Suggestion will be appriciable at this great moment!!

I would recommend that you use the /WARN=ENABLE=(LEVEL4, QUESTCODE) and
first fix all of the warning messages, and then work on removing all of
the informational messages. There may be some informational messages
that you can not remove and those can be suppressed with #pragma message
disable xxxxxx in the code.

Also start looking at where you can add the "const" modifier to function
declarations and prototypes.

This enables the compiler to better optimize the modules that call those
routines, and such optimizations can be very important to I64 and Alpha
programs. It may also detect some more bugs.

In addition, any variables that are initialized at compile time and
never changed by the program should get a "const" modifier for the same
reasons.

Pointer variables that always point to constant data that is not
modified should also get this modifier.

-John
wb8tyw@qsl.network
Personal Opinion Only



Relevant Pages

  • Re: decrement past beginning is valid?
    ... > What I meant by legal is that a compiler will compile it. ... > that an array is the same as a pointer. ... behave the same way on all platforms. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: gdb not catching out-of-bounds pointer
    ... is also not defined by the C-standard, IOW: writing code in anything ... provided the library writer knows what the compiler writer guarantees ... etc.) that don't point into the same array than I would about the sort ... of pointer aliasing issue that started this sub-thread. ...
    (comp.unix.programmer)
  • Re: lockless file descriptor lookup
    ... It isn't clear whether you want to refresh the fd_ofiles pointer to the ... the array, or the fd'th element. ... This is actually intended to catch cases where the descriptor array has expanded and the pointer to fd_ofiles has changed, or the file has been closed and the pointer at the fd'th element has changed. ... I'm attempting to force the compiler to reload the fd_ofiles array pointer from the fdp structure. ...
    (freebsd-arch)
  • Re: null terminated strings
    ... pointer + 1 will point to the next element in the array. ... What I don't understand is why such a thing was included in any language that's more than an assembler. ... of structures that are not 'natural' the compiler need to generate ADD instructions using sizeof. ...
    (comp.os.vms)
  • Re: char **argv & char *argv[]
    ... "pointer to pointer to char". ... >> pointer)) pointing to the first element of an array. ... so we have to start adding more context. ... type "pointer to char", rather than "array MISSING_SIZE of char". ...
    (comp.lang.c)