Operating System - Linux
1752796 Members
5902 Online
108789 Solutions
New Discussion юеВ

Ansi C compiler Linux vs. HPUX

 
Scott McDade
Frequent Advisor

Ansi C compiler Linux vs. HPUX

Hello all:

I am trying to port some old Ansi C source code to Linux that was originally written and compiled on a HPUX machine. I would like to try and resolve this warning in the following code. It compiles without issue in HPUX.

ACME.c:227: warning: assignment makes integer from pointer without a cast

Problematic Code:

/* Strip off the directory path to the testspec, RKEEP */
strcpy(buf,Get_tag(&systemtag,"SYS_COMMENT",4));
while (strstr(buf,"/") != NULL) {
strcpy(buf,strstr(buf,"/")+1); }
printf("WOW =%s\n",buf);
Tmmp1=strstr(buf,"qk"); // Problem
Tmmp2=strstr(buf,"as"); // Problem
printf("Tmmp1: %d\n",Tmmp1);


Keep it Simple!~
7 REPLIES 7
Steven Schweda
Honored Contributor

Re: Ansi C compiler Linux vs. HPUX

It would be easier to puzzle this out if
someone besides you knew which line was 227.
Still easier, if you supplied a whole failing
test program, instead of a fragment which
can't be compiled. (I can be at least as
lazy in debugging your problem as you can be
in presenting it.)

> It compiles without issue in HPUX.

Using which compiler? And what are you using
on your (unspecified) Linux system?

(I assume that you mean "without problems" or
"without complaints", rather than "without
issue". A compiler without issue is pretty
much a no-op.)
Scott McDade
Frequent Advisor

Re: Ansi C compiler Linux vs. HPUX

Hello Steven:

Thanks for the response.

I have denoted line 227 with //Problem in the snipet. Sorry about that.

I pretty sure for HPUX we are using cc and for Linux we are using gcc.

Yes, I mean it compiles in HPUX without any WARNINGS. But in Linux it give the the aforementioned WARNING.

Thanks.

Keep it Simple!~
Steven Schweda
Honored Contributor

Re: Ansi C compiler Linux vs. HPUX

> [...] for HPUX we are using cc [...]

Version(s)?

> [...] for Linux we are using gcc [...]

Version?

But none of the usually useful info may make
any difference, because there's not enough
code here to identify a problem.

Can't see the "#include" directives.
Can't see the declarations of anything.
Can't see the compiler command(s).

Either I'm missing some obvious things, or
you failed to include them in your problem
description.

I might be able to write a program which
includes your program fragment, and which
either triggers similar complaints or not,
but my program would not be your program, and
there's no reason to imagine that solving any
problems with my program would help yours.

I'm still just as lazy as I was before. You,
too, apparently. If you would like actual
help with a program, try providing an actual
program. (Or try a psychic hotline. My
remote viewing ability is practically
nonexistent.)
Scott McDade
Frequent Advisor

Re: Ansi C compiler Linux vs. HPUX

Hello

gcc rev is 3.4.5-2, the HPUX cc compiler version is unknown at this point as the box is offline.

I have a attached source file. Check out line 226 and 227 I believe the problem has to do with type cast of Tmmp1 and Tmmp2 and buf. I have tried many combinations without success.
Keep it Simple!~
Steven Schweda
Honored Contributor

Re: Ansi C compiler Linux vs. HPUX

> I have a attached source file. [...]

But not "tbldata.h", making it a bit tough to
compile.

C comments delimited by "#"? Not very
portable:

alp $ cc /list 306754.c

#*****************************************************************************
.^
%CC-W-BADDIRECTIVE, "*" is an invalid preprocessor directive, and is being ignor
ed.
at line number 1 in file ALP$DKA0:[SMS.ITRC]306754.C;1


Line 148:

int wff, badd, DoNot, , Tmmp2, cob, boo, ick, idoit, tstnam;

So Tmmp2 is explicitly an "int". There's no
sign of a declaration of Tmmp1 (although
there is a suspicious hole), so it's
implicitly an "int".

dy # grep 'strstr(' /usr/include/*.h
/usr/include/string.h: extern char *strstr(const char *, const char *);
/usr/include/string.h: extern char *strstr();

(Or "man strstr".)

So strstr() is char *.

Thus
Tmmp1=strstr([...])
Tmmp2=strstr([...])
store a pointer into an "int", hence the
complaints. If you're storing pointers, put
them into pointers:

char *Tmmp1;
char *Tmmp2;
Steven Schweda
Honored Contributor

Re: Ansi C compiler Linux vs. HPUX

For another opinion:

alp $ cc /version
HP C V7.3-009 on OpenVMS Alpha V7.3-2

alp $ type 306754_x2.C
#include

main()
{
char buf[1024];
int Tmmp2;

Tmmp1=strstr(buf,"qk");
Tmmp2=strstr(buf,"as");
}

alp $ cc 306754_x2.C

Tmmp1=strstr(buf,"qk");
....^
%CC-E-UNDECLARED, In this statement, "Tmmp1" is not declared.
at line number 8 in file ALP$DKA0:[SMS.ITRC]306754_X2.C;1

Tmmp2=strstr(buf,"as");
....^
%CC-W-CVTDIFTYPES, In this statement, "strstr(...)" of type "pointer to char", is being converted to "int".
at line number 9 in file ALP$DKA0:[SMS.ITRC]306754_X2.C;1
Steven Schweda
Honored Contributor

Re: Ansi C compiler Linux vs. HPUX

By the way:

alp $ type 306754_ok.c
#include

main()
{
char buf[1024];
char *Tmmp1;
char *Tmmp2;

Tmmp1=strstr(buf,"qk");
Tmmp2=strstr(buf,"as");
}
alp $ cc 306754_ok.c
alp $