again a newbie... :( compiler problems

T

Thorsten Kaben

hello there!

i'm sorry to bother you because of this but i'm today a newbie again.
:( first excause my english! round about six years ago i stopped
programming in cpp. at this time all my programs are compiled without
problems and of course they worked all fine. but now (after six years)
i had problems to compile anything with djgpp (rhide).

i think the problems are only compiler/linker switches but i don't know
more whitch that are. :( okay, here the compiler errors (repeated
serval times):

Compiling: accel.cpp
gambler.h(98) Error: error: using typedef-name 'xxx' after 'struct'
gambler.h(51) Error: error: 'xxx' has a previous declaration here
gambler.h(98) Error: error: invalid type in declaration before ';'
token
--- repeated for many defs ---
In function 'void run_acc(int)':
accel.cpp(31) Error: error: request for member 'xxx' in 'xxx', which is
of non-class type 'int'
--- repeated for many members ---

i hope you have a solution for me! ;) as i say... i think it is only a
compiler/linker switch... but whitch!? many thanks in advance!

th.kaben.
 
A

Alf P. Steinbach

* Thorsten Kaben:
hello there!

i'm sorry to bother you because of this but i'm today a newbie again.
:( first excause my english! round about six years ago i stopped
programming in cpp. at this time all my programs are compiled without
problems and of course they worked all fine. but now (after six years)
i had problems to compile anything with djgpp (rhide).

i think the problems are only compiler/linker switches but i don't know
more whitch that are. :( okay, here the compiler errors (repeated
serval times):

Compiling: accel.cpp
gambler.h(98) Error: error: using typedef-name 'xxx' after 'struct'
gambler.h(51) Error: error: 'xxx' has a previous declaration here
gambler.h(98) Error: error: invalid type in declaration before ';'
token
--- repeated for many defs ---
In function 'void run_acc(int)':
accel.cpp(31) Error: error: request for member 'xxx' in 'xxx', which is
of non-class type 'int'
--- repeated for many members ---

i hope you have a solution for me! ;) as i say... i think it is only a
compiler/linker switch... but whitch!? many thanks in advance!

See the FAQ item "How do I post a question about code that doesn't work
correctly?", currently at <url:
http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.8>.
 
T

Thorsten Kaben

Alf said:
See the FAQ item "How do I post a question about code that doesn't work
correctly?", currently at <url:
http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.8>.

okay, i'm sorry about this! but i thought it was not really important
whitch version etc, because of i thought it could only be a switch.

rhide 1.5 / gcc 4.10 / make 3.791 / gdb 6.11 under winxp pro. i hope
it's enough. because there couldn't be a failure in the code - it was
compiled under the same env six years ago without problem. only the
versions of the gcc etc are different.
 
A

Alf P. Steinbach

* Thorsten Kaben:
okay, i'm sorry about this! but i thought it was not really important
whitch version etc, because of i thought it could only be a switch.

rhide 1.5 / gcc 4.10 / make 3.791 / gdb 6.11 under winxp pro. i hope
it's enough. because there couldn't be a failure in the code - it was
compiled under the same env six years ago without problem. only the
versions of the gcc etc are different.

Read the FAQ item, it says something about example code...
 
T

Thorsten Kaben

Read the FAQ item, it says something about example code...

the accel.cpp

#include <math.h>
#include "gambler.h"

const double pi=3.1415926535;

struct t_pos {long x; long y;};
struct t_real_pos {double x; double y;};

t_real_pos disp_f;
t_pos ship, disp;

long start_x=0, start_y=0, way_x=0, way_y=0, delta_x=0, delta_y=0;
double heading=0, full_dist=0, travel_dist=0;
int speed=0;

long sign(double r)
{
if (r<0) return -1;
else
if (r>0) return 1;
return 0;
}

double rad_to_bogen(double Rad)
{
return ((Rad*360)/(2*pi));
}

void run_acc(int snum)
{
speed = ship_dat[snum].wWarp;
start_x = ship_dat[snum].wXShip;
start_y = ship_dat[snum].wYShip;
ship.x = ship_dat[snum].wXShip;
ship.y = ship_dat[snum].wYShip;
way_x = ship_dat[snum].wXWay;
way_y = ship_dat[snum].wYWay;
delta_x = way_x;
delta_y = way_y;
full_dist = sqrt((delta_x*delta_x)+(delta_y*delta_y));
travel_dist = (speed*speed*gambler_cfg.factor)-(speed*speed);

if (delta_x==0) heading=270-rad_to_bogen(atan(delta_x/delta_y));
if (delta_y==0) heading=270-rad_to_bogen(atan(delta_y/delta_x));

while (heading>360) heading-=360;

if (travel_dist<full_dist)
{
disp_f.x=travel_dist*cos(heading)*sign(travel_dist*cos(heading));
disp_f.y=travel_dist*sin(heading)*sign(travel_dist*sin(heading));

disp.x=long (disp_f.x)+sign(disp_f.x);
disp.y=long (disp_f.y)+sign(disp_f.y);

ship_dat[snum].wXShip=ship_xy[snum].pos.x=start_x+disp.x;
ship_dat[snum].wYShip=ship_xy[snum].pos.y=start_y+disp.y;

ship_dat[snum].wXWay=way_x+disp.x;
ship_dat[snum].wYWay=way_y+disp.y;
}
else
{
if ((ship_dat[snum].wXWay!=0) || (ship_dat[snum].wYWay!=0))
{

ship_dat[snum].wXShip=ship_xy[snum].pos.x=start_x+ship_dat[snum].wXWay;

ship_dat[snum].wYShip=ship_xy[snum].pos.y=start_y+ship_dat[snum].wYWay;
ship_dat[snum].wXWay=0;
ship_dat[snum].wYWay=0;
}
}
}

the gambler.h

#ifndef GAMBLER_H
#define GAMBLER_H

#include "vgapdefs.h"

// gambler.cfg
typedef struct
{
bool log;
bool host999;
bool phost;
bool defcon;
bool give_planet;
bool give_planet_clans;
bool market;
bool plumber;
bool starbank;
bool superbase;
bool trader;
bool wormholes;
bool wormholes_eat_ships;
bool alliance;
char alliance_num;
float factor;
int beam_sweep_mines;
int beam_sweep_webs;
int fighter_sweep_mines;
int fighter_sweep_webs;
bool only_colonies;
bool scoop_enemy;
unsigned int add_fighterbay_cost;
unsigned int add_tube_cost;
unsigned int add_weapon_cost;
unsigned int update_engine_cost;
unsigned int update_tube_cost;
unsigned int update_weapon_cost;
bool want_marketmail[12];
char first[51];
char last[51];
char markets;
bool centre_market;
unsigned int repair_damage;
unsigned int fill_crew;
unsigned int shit_call;
bool acc;
bool want_wormmail[12];
bool give_planet_allow_bird;
bool scoop_own;
bool trader_allow_ally_buy;
bool surrender;
} gcfg;

// gaccount.dat
typedef struct
{
unsigned long mc;
unsigned long su;
unsigned long ne;
unsigned long tr;
unsigned long du;
unsigned long mo;
unsigned long old_mc;
unsigned long old_su;
unsigned long old_ne;
unsigned long old_tr;
unsigned long old_du;
unsigned long old_mo;
} gaccount;

// gwhole.dat
typedef struct
{
char owner;
int x1;
int y1;
int damage1;
int x2;
int y2;
int damage2;
int number;
char visible1[12];
char visible2[12];
} gholedat;

// gtrader.dat
typedef struct
{
int owner;
int price;
} g_trader_dat;

// gdefcon.dat
typedef struct
{
char race[12];
} g_defcon_dat;

extern struct gcfg gambler_cfg;
extern struct gaccount account[12];
extern struct gholedat hole_dat[501];
extern struct auxdatahst aux_dat;
extern struct greytype grey_dat;
extern struct racenm race_name[12];
extern struct shipxy ship_xy[1001];
extern struct shipdata ship_dat[1001];
extern struct planetcoords planet_xy[501];
extern struct planetname planet_name[501];
extern struct planetdata planet_dat[501];
extern struct basedata base_dat[501];
extern struct minedata mine_dat[501];
extern struct rconfig ref_dat;
extern struct hullspec hull_dat[121];
extern struct beamspec beam_dat[11];
extern struct torpspec torp_dat[11];
extern struct engspec eng_dat[10];
extern struct ufodata ufo_dat[1001];
extern struct genhost gen_dat;
extern struct hconfig hconfig_dat;
extern struct g_trader_dat trader_dat[1001];
extern struct g_defcon_dat defcon_dat[12];

extern unsigned int trp; // Anzahl der Trader-Planet-FC's
extern unsigned int sur; // Anzahl der Surrender-Kommandos
extern unsigned int dc; // Anzahl der Defcon-FC's
extern UB2 ub2_dummy1, ub2_dummy2, ub2_dummy3, ub2_dummy4; // Dummys
extern bool overwrite; // Erstelle / berschreibe gaccount.dat!?

extern char* v;
extern char* homepath;
extern char* gamepath;
extern char* logfile;
extern int _argc;
extern char** _argv;

extern unsigned int turn;

void deinit_program(void);
void say_error(char* error);
double round(double wert);
int pos(char* str, char* sub_str);
char* add_slash(char* str);
char* prg_dir(void);
bool check_params(char* param);
bool bit_gesetzt(int zahl, int bit_nr);

#endif
 
T

Thomas Tutone

Thorsten said:
okay, i'm sorry about this! but i thought it was not really important
whitch version etc, because of i thought it could only be a switch.

What Alf is saying is that if you don't post the code, there is little
we can do to help you. (And make sure you keep the code _short_ and
_complete_.)
rhide 1.5 / gcc 4.10 / make 3.791 / gdb 6.11 under winxp pro. i hope
it's enough. because there couldn't be a failure in the code - it was
compiled under the same env six years ago without problem. only the
versions of the gcc etc are different.

You're mistaken. gcc six years ago was vastly different that it is
today. The current version conforms much more closely to the C++
standard than the older version. As a result, code that compiled on
your six-year old compiler may nonetheless be code that violates the
C++ standard and cannot be compiled on the newer compiler unless you
first fix the code.

Good luck.

Best regards,

Tom
 
D

Default User

Thorsten said:
okay, i'm sorry about this! but i thought it was not really important
whitch version etc, because of i thought it could only be a switch.


What Alf means is, Show Us The Code!




Brian
 
T

Thorsten Kaben

You're mistaken. gcc six years ago was vastly different that it is
today. The current version conforms much more closely to the C++
standard than the older version. As a result, code that compiled on
your six-year old compiler may nonetheless be code that violates the
C++ standard and cannot be compiled on the newer compiler unless you
first fix the code. Good luck.

okay... that may be... but i know i had some compiler switches set in
the past. but i can't remember me... :(

perhaps can anybody help me to solve the problem!? many thanks!
 
I

Ian Collins

Thorsten said:
the accel.cpp

Is this supposed to be C or C++? If the latter , why all the typedefs?

Either way, you can't typedef a struct XX and then use 'struct XX' for a
variable, just use XX.

<snip>
 
T

Thorsten Kaben

Is this supposed to be C or C++? If the latter , why all the typedefs?

c++
Either way, you can't typedef a struct XX and then use 'struct XX' for a
variable, just use XX.

i'm sorry... must say that i don't understand what you want to say... i
think i had to define a struct before i can use it!? but excause my
knowledge... it's six years ago and i try to remember me at the
moment...

it would really help if someone could show me a way to fix the compile
errors with a example out of my code...
 
A

Alf P. Steinbach

* Thorsten Kaben:
the gambler.h

#ifndef GAMBLER_H
#define GAMBLER_H

#include "vgapdefs.h"

Error, no such header.

// gambler.cfg
typedef struct
{ [snip]
} gcfg;

In C++, use the form

struct Name {};

instead of

typedef struct {} Name;

By the way, the above is C code, not C++ code, at least in spirit. In
C++, use constructors and destructors to initialize and clean up.


[snip]
extern struct gcfg gambler_cfg;

Remove the word 'struct'.


[snip]
the accel.cpp

#include <math.h>
#include "gambler.h"
[snip]

void run_acc(int snum)
{
speed = ship_dat[snum].wWarp;

You haven't shown the definition for 'shipdata', the array element type,
so it's impossible to say whether it has a member wWarp.
 
T

Thorsten Kaben

You haven't shown the definition for 'shipdata', the array element type,
so it's impossible to say whether it has a member wWarp.

okay... that could help me further! :) many thanks for the first! i'll
try to fix the problems like you show me and report the result later! ;)
 
I

Ian Collins

Thorsten said:
c++
Sure looks like C to me.



i'm sorry... must say that i don't understand what you want to say... i
think i had to define a struct before i can use it!? but excause my
knowledge... it's six years ago and i try to remember me at the
moment...

it would really help if someone could show me a way to fix the compile
errors with a example out of my code...
Just remove the 'struct' from the lines like

extern struct gcfg gambler_cfg;

And while you are there, change your struct declarations to C++ as Alf
suggested.
 
T

Thorsten Kaben

okay... i've fixed this problem, many thanks again to all! but now i've
the next. it looks that the function alloca is no more declared as in
the past. this code works in the past:

void check_allies(void)
{
int num[12];
bool to_much[12];

char* text;

for (int i=1; i<=11; i++)
{
to_much=false;

if (gen_dat.wPlaying)
for (int j=1; j<=11; j++)
{
num=0;

if (ally_offer(i, j)) num++;
if (num>gambler_cfg.alliance_num)
{
printf("Gambler: Alliance watcher ... race #%u has to much
allies!\n", i);
log("Alliance watcher: Race #% has to much allies!", i);
printf("Gambler: Alliance watcher ... deleting all alliances of
race #%u.\n", i);
log("Alliance watcher: Deleting all alliances of race #%.", i);
delete_alliances(i); to_much=true; break;
}
}

if (to_much)
{
text=(char*) alloca(250); bzero(text,250);
strcat(text, "(-h000)<<< Alliance Watcher Info! >>>\r\r");
strcat(text, "You has more alliances closed or offered\r");
strcat(text, "as allowed within this game! Because of\r");
strcat(text, "this all your alliances are canceled!\r\r");
strcat(text, "Bye, The Gambler's Alliance Watcher.");
write_mail(i, text);
}
}
write_auxdata_and_grey_hst();
}

but now: error: 'alloca' was not declared in this scope. i've looked
into the help and it says:

void *alloca(size_t _size);

but why does "text=(char*) alloca(250); bzero(text,250);" not work?
 
A

Alf P. Steinbach

* Thorsten Kaben:
if (to_much)
{
text=(char*) alloca(250); bzero(text,250);
strcat(text, "(-h000)<<< Alliance Watcher Info! >>>\r\r");
strcat(text, "You has more alliances closed or offered\r");
strcat(text, "as allowed within this game! Because of\r");
strcat(text, "this all your alliances are canceled!\r\r");
strcat(text, "Bye, The Gambler's Alliance Watcher.");
write_mail(i, text);
}
}
write_auxdata_and_grey_hst();
}

but now: error: 'alloca' was not declared in this scope. i've looked
into the help and it says:

void *alloca(size_t _size);

but why does "text=(char*) alloca(250); bzero(text,250);" not work?


'alloca' is not a standard C++ function. However, you don't need it for
what you're doing above, a fixed size stack allocation; you could just
use a local variable for that. And unless 'write_mail' changes the
contents of the buffer you don't even need that local variable; you
could do by simply using a literal string constant, e.g.

static char const text[] =
"bla bla"
"bla bla"
"bla bla";
 
D

Default User

Thorsten Kaben wrote:

void *alloca(size_t _size);

but why does "text=(char*) alloca(250); bzero(text,250);" not work?


That's a non-standard function, so's bzero() for that matter. About the
best we can tell you is to make sure you have the headers that your
documention specifies included.




Brian
 
T

Thorsten Kaben

'alloca' is not a standard C++ function. However, you don't need it for
what you're doing above, a fixed size stack allocation; you could just
use a local variable for that. And unless 'write_mail' changes the
contents of the buffer you don't even need that local variable; you
could do by simply using a literal string constant, e.g.

static char const text[] =
"bla bla"
"bla bla"
"bla bla";

it does not change the contents. you mean like this(?):

static char const text[] ="(-h000)<<< Alliance Watcher Info! >>>\r\r"
"You has more alliances closed or offered\r"
"as allowed within this game! Because of\r"
"this all your alliances are canceled!\r\r"
"Bye, The Gambler's Alliance Watcher.";
write_mail(i, text);

what is with the assigned mem if the function ends? is it then free?
and what i have to do if the contents would be changed?

what about this(?):

void run_battle(void)
{
char* tmp_str[12];
char* text=(char*) alloca(250);

for (int i=1; i<=11; i++)
{
tmp_str=(char*) alloca(100);
bzero(tmp_str,100);
}

bzero(text,250);

bzero does nothing more/less as filling the assigned mem with zeros.

and here comes this error: c++ forbids assignment of arrays

for (int i=1; i<=999; i++)
{
switch (ship_dat.wRace)
{
case 1 :ship_dat.sCode="501"; break;
case 2 :ship_dat.sCode="502"; break;
case 3 :ship_dat.sCode="503"; break;
case 4 :ship_dat.sCode="504"; break;
case 5 :ship_dat.sCode="505"; break;
case 6 :ship_dat.sCode="506"; break;
case 7 :ship_dat.sCode="507"; break;
case 8 :ship_dat.sCode="508"; break;
case 9 :ship_dat.sCode="509"; break;
case 10:ship_dat.sCode="510"; break;
case 11:ship_dat.sCode="511"; break;
}

ship_dat.wWarp=0;
ship_dat.wXWay=0;
ship_dat.wYWay=0;
ship_dat.wXShip=2000;
ship_dat.wYShip=2000;
ship_dat.wMission=4;
ship_dat.wEnemy=0;
ship_dat.wTowed=0;
if (!ship_dat.wFuel) ship_dat.wFuel=10;
ship_dat.wInterceptShip=0;
ship_xy.pos.x=2000;
ship_xy.pos.y=2000;
}
}

how could i fix this? there must be many changes in the gcc since my
last prog... :-(
 
A

Alf P. Steinbach

* Thorsten Kaben:
'alloca' is not a standard C++ function. However, you don't need it for
what you're doing above, a fixed size stack allocation; you could just
use a local variable for that. And unless 'write_mail' changes the
contents of the buffer you don't even need that local variable; you
could do by simply using a literal string constant, e.g.

static char const text[] =
"bla bla"
"bla bla"
"bla bla";

it does not change the contents. you mean like this(?):

static char const text[] ="(-h000)<<< Alliance Watcher Info! >>>\r\r"
"You has more alliances closed or offered\r"
"as allowed within this game! Because of\r"
"this all your alliances are canceled!\r\r"
"Bye, The Gambler's Alliance Watcher.";

This OK, assuming that \r\r instead of \n is intentional.

write_mail(i, text);

If the 'write_mail' second argument is not declared 'const', it should be.


what is with the assigned mem if the function ends? is it then free?

It's a named constant. The memory is allocated once and for all when
the program starts.

and what i have to do if the contents would be changed?

Use a variable insted of a constant.

what about this(?):

void run_battle(void)
{
char* tmp_str[12];
char* text=(char*) alloca(250);

for (int i=1; i<=11; i++)
{
tmp_str=(char*) alloca(100);
bzero(tmp_str,100);
}


If alloca had been a standard function you could use, this would be a
recipe for disaster, assuming 'tmp_str' is used for something.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top