View previous topic :: View next topic |
Author |
Message |
Eowyn n00b
Joined: 01 Jun 2002 Posts: 21
|
Posted: Tue Dec 03, 2002 9:28 pm Post subject: C programming question |
|
|
Hi this is just a question about an old game i found called Galactic Bloodshed
i have the source code for it but i get a compile error when i try to compile it on gentoo
Code: |
tele.c: In function `post':
tele.c:117: warning: assignment discards qualifiers from pointer target type
tele.c:127: warning: assignment makes pointer from integer without a cast
tele.c:129: dereferencing pointer to incomplete type
tele.c:129: dereferencing pointer to incomplete type
tele.c:129: dereferencing pointer to incomplete type
tele.c:130: dereferencing pointer to incomplete type
tele.c:130: dereferencing pointer to incomplete type
tele.c: In function `push_telegram':
tele.c:165: warning: assignment makes pointer from integer without a cast
tele.c:168: dereferencing pointer to incomplete type
tele.c:168: dereferencing pointer to incomplete type
tele.c:168: dereferencing pointer to incomplete type
tele.c:169: dereferencing pointer to incomplete type
tele.c:169: dereferencing pointer to incomplete type
make[1]: *** [tele.o] Error 1
make[1]: Leaving directory `/root/blood/gb-HUT-5.1.1/user'
make: *** [all] Error 2
|
is the error
and
Code: | Void post(const char *msg, int type) {
char telefl[100];
char pbuf[1024];
FILE *news_fd;
char *p;
memset((char *)telefl, 0, sizeof(telefl));
switch (type) {
case DECLARATION:
sprintf(telefl, "%s", DECLARATIONFL);
break;
case TRANSFER:
sprintf(telefl, "%s", TRANSFERFL);
break;
case COMBAT:
sprintf(telefl, "%s", COMBATFL);
break;
case ANNOUNCE:
sprintf(telefl, "%s", ANNOUNCEFL);
break;
default:
return;
}
for (p = msg; *p; p++) {
if (*p == ';')
*p = '\n';
else
if (*p == '|')
*p = '\t'; if ((news_fd = fopen(telefl, "a")) != NULL) {
tm = time(0);
current_tm = localtime(&tm);
sprintf(pbuf, "%2d/%2d %02d:%02d:%02d %s",
current_tm->tm_mon + 1, current_tm->tm_mday, current_tm->tm_hour,
current_tm->tm_min, current_tm->tm_sec, msg);
fprintf(news_fd, "%s", pbuf);
fclose(news_fd);
newslength[type] += strlen(pbuf)
}
}
void push_telegram(int recpient, int gov, const char *msg)
{
char telefl[100];
FILE *telegram_fd;
memset((char *) telefl, 0, sizeof(telefl));
sprintf(telefl, "%s.%d.%d", TELEGRAMFL, recpient, gov);
if ((telegram_fd = fopen(telefl, "a")) == NULL)
if ((telegram_fd = fopen(telefl, "w+")) == NULL) {
perror("teleg_send");
return;
}
tm = time(0);
current_tm = localtime(&tm);
fprintf(telegram_fd, "%2d/%2d %02d:%02d:%02d %s\n",
current_tm->tm_mon + 1, current_tm->tm_mday, current_tm->tm_hour,
current_tm->tm_min, current_tm->tm_sec, msg);
fclose(telegram_fd);
} |
is the code that seems to break
this game will compile on older debian installs but not gentoo
any help welcom
thanks
Colin[/code] |
|
Back to top |
|
|
rac Bodhisattva
Joined: 30 May 2002 Posts: 6553 Location: Japanifornia
|
Posted: Tue Dec 03, 2002 10:07 pm Post subject: |
|
|
Does that file #include <stdio.h>? If not, does adding that line help matters any? _________________ For every higher wall, there is a taller ladder |
|
Back to top |
|
|
choward Tux's lil' helper
Joined: 08 Nov 2002 Posts: 92
|
Posted: Tue Dec 03, 2002 10:47 pm Post subject: |
|
|
Try adding a at the beginning of the file
I expect that the lines that are causing you problems are:
Code: |
current_tm->tm_mon + 1, current_tm->tm_mday, current_tm->tm_hour,
current_tm->tm_min, current_tm->tm_sec, msg);
|
and
Code: |
current_tm->tm_mon + 1, current_tm->tm_mday, current_tm->tm_hour,
current_tm->tm_min, current_tm->tm_sec, msg);
|
They're the only lines I can see that dereference a non-basic type. If I'm wrong, can you point out which lines exactly cause the errors? _________________ Craig Howard
4B Computer Science -- University of Waterloo |
|
Back to top |
|
|
Eowyn n00b
Joined: 01 Jun 2002 Posts: 21
|
Posted: Wed Dec 04, 2002 1:08 am Post subject: |
|
|
Code: | static time_t tm;
static FILE *teleg_read_fd;
static char telegram_file[PATHLEN];
static struct stat telestat;
#include "proto.h"
static struct tm *current_tm; /* for watching for next update */
|
i think its one of these lines that is causeing the problem
after adding
#include <time.h>
to just before
Void post(const char *msg, int type)
it compiles fine
thanks for the help |
|
Back to top |
|
|
duff Guru
Joined: 19 Jun 2002 Posts: 466 Location: Clemson, SC
|
Posted: Wed Dec 04, 2002 2:08 pm Post subject: |
|
|
Eowyn wrote: | Code: | static time_t tm;
...
static struct tm *current_tm; /* for watching for next update */
|
|
Eh?? Is "tm" supposed to be a struct or a variable? |
|
Back to top |
|
|
Eowyn n00b
Joined: 01 Jun 2002 Posts: 21
|
Posted: Wed Dec 04, 2002 9:38 pm Post subject: |
|
|
duff wrote: |
Eh?? Is "tm" supposed to be a struct or a variable? |
i have no idea sorry
im just trying to get the game compiled so me and a few people can get play
Eowyn |
|
Back to top |
|
|
rac Bodhisattva
Joined: 30 May 2002 Posts: 6553 Location: Japanifornia
|
Posted: Wed Dec 04, 2002 9:53 pm Post subject: |
|
|
[/rac shakes the cobwebs and dust out of her white barrister wig and enters language lawyer mode]
A8.3 Structure and Union Declarations
A type specifier of the form struct-or-union identifier { struct-declaration-list } declares the identifier to be the tag of the structure or union specified by the list. [...] The names of members and tags to not conflict with each other or with ordinary variables. (K&R 2nd ed., pp. 212-3)
So it's perfectly OK to have a "struct tm" and a variable named tm in the same scope. One thing I learned when researching this is that the first edition of K&R allowed compilers to just have one big honking namespace for all structure members, so a C compiler that disallowed two structs having members with the same name would have been OK. The second edition ensures that you can have a member named 'm' in both struct t1 and struct t2. _________________ For every higher wall, there is a taller ladder |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|