LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-18-2008, 09:11 AM   #1
knobby67
Member
 
Registered: Mar 2006
Posts: 627

Rep: Reputation: 43
errors converting from C to C++


Hi all,
I'm an assembler/C programmer who has to convert my code over to run on C++, so with hope in my heart I changed my makefile gcc to g++. Surprisingly most seemed to compile OK, except for a series of errors all related to similar function calls, the errors are all like

common/ModelLoader.c: In function ‘void LoadLights(FILE*, MODEL*)’:
common/ModelLoader.c:116: error: invalid conversion from ‘void*’ to ‘light*’

and relate to mallocing structures inside structures

so the above error is produced from the line

model->number_of_lights=number_of_lights;
model->light = malloc (sizeof (LIGHT) * number_of_lights); THIS IS LINE 116

Can anyone advise what I need to do to make this run in C++ (g++)
I'm using etch and g++ 4.1.1 if that matters.

my C structure is
typedef struct model
{

int number_of_materials;
struct texture *material; /*list of materials used */

struct camera *camera; /*model cameras */
int number_of_lights;
struct light *light; /*light numbers positions etc*/
.....


which uses a structure

typedef struct light
{

float pos[3];
float lookat[3];
float ambient[4];
float diffuse[4];
float specular[4];

uint spotlight;

GLuint lightid;

}LIGHT;


I'm I allowed to use structures inside structures in C++.

Thanks in advance
 
Old 01-18-2008, 09:31 AM   #2
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
The return value of malloc must be cast to the type in cpp. Consider using c++ code and not c in cpp ie typedefs where none are needed, struct keyword where not needed, new delete instead of malloc free, using constructors, destructors, member functions etc.

Last edited by dmail; 01-18-2008 at 09:32 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
converting Screener Linux - Newbie 14 07-02-2006 10:02 PM
Errors, Errors, and more Errors (KDE 3.4.x GUI Errors) Dralnu Linux - Software 2 05-13-2006 08:30 AM
Converting c++ comments to c markjuggles Programming 1 10-17-2005 03:33 PM
converting fs nautilus_1987 Linux - Hardware 4 11-03-2002 05:08 PM
Outlook converting bkeating Linux - General 8 06-02-2002 07:08 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration