473,473 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

going from c to c++

Hi

I need some help, in syntax, going from c to c++

how will the following syntax be written in c++ using the new statement

if ((new_table->table = malloc(sizeof(list_t *) * size)) == NULL) {
return NULL;

here are the struct definitions

struct createList
{
int data;
createList *list;
};

struct createTable
{
int table_size;
createList **table;
};

new_table is an instance of createTable.

Any help will be appreciated

thanks

nimesh

Jan 24 '07 #1
3 1386
I need some help, in syntax, going from c to c++

One of the main misleadings in going from C to C++ is thinking that
they differ by syntax only :-D.
Feel free to use malloc in C-like code -- there is absolutely no sence
in new statement in your code. Or use classes like std::list ot
std::vector instead.

Jan 24 '07 #2

ni**************@gmail.com napsal:
Hi

I need some help, in syntax, going from c to c++

how will the following syntax be written in c++ using the new statement

if ((new_table->table = malloc(sizeof(list_t *) * size)) == NULL) {
return NULL;

here are the struct definitions

struct createList
{
int data;
createList *list;
};

struct createTable
{
int table_size;
createList **table;
};

new_table is an instance of createTable.

Any help will be appreciated

thanks

nimesh
If you are compiling code whic uses malloc with C++ compiler, you have
to typecast result of malloc to correct type, because malloc returns
void*. You do not need to do anything else (in this case).

Jan 24 '07 #3
ni**************@gmail.com wrote:
Hi

I need some help, in syntax, going from c to c++

how will the following syntax be written in c++ using the new statement

if ((new_table->table = malloc(sizeof(list_t *) * size)) == NULL) {
return NULL;
new_table->table = new createList*[size];

A null pointer check is not needed, since operator new never returns a null
pointer. It throws an exception if it can't allocate.
here are the struct definitions

struct createList
{
int data;
createList *list;
};

struct createTable
{
int table_size;
createList **table;
};

new_table is an instance of createTable.
Jan 24 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

81
by: julio | last post by:
Sorry but there is no another way, c# .net and mono are going to rip python, not because python is a bad lenguage, but because is to darn old and it refuses to innovate things, to fix wrong things,...
32
by: Fresh Air Rider | last post by:
Hi I understand that ASP.net 2.0 (Whidbey) is going to reduce coding by 70%. Surely this is going to de-skill or dumb down the developer's task and open up the task of web development to less...
4
by: nospam | last post by:
HtmlSelect has a method called OnServerChange that supposed to detect whether the control (select) has changed on a postback. This is not all that useful. It should be like the asp.net...
3
by: Rod | last post by:
In Dino Esposito's book, "Programming Microsoft ASP.NET", there is a chapter titled, "ASP.NET State Management". There is a section in there discussing session state sometimes going away. He...
3
by: needin4mation | last post by:
Is the framework going to change so that on sorting it will have some way of letting you sort two ways, asc or desc? Is the framework's paging going to change so that it does not bring back the...
41
by: Rob R. Ainscough | last post by:
I keep hearing persistant rumors (along with my own experience) that .NET is going to be abandon by Microsoft due to performance & security issues? I realize no one from Microsoft is likely to...
12
by: Jeff | last post by:
Looking for your highly subjective opinions (from those of you who have been working extensively with VS 2005). I have a client that needs/wants a complete rewrite of an existing application. I...
0
by: MikeY | last post by:
Hi everyone, I posted a question very early today, but maybe I wasn't articulate enough. Hopefully this will illicit a response I've created a windows form and a User Control. This is a...
1
by: Bigeloww | last post by:
Dollar is going to rise! Good news for US http://my.usatodays.us/money/myusatoday.html ---------------------------------- http://community.ihostasp.net ASP.NET Developer Community
22
by: Rickster66 | last post by:
As Instructed this is a new thread regarding my original post: "Select Only 10 Columns Going Back" I'm sorry for the late response. I've been gathering up information and carefully with as much...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.