473,698 Members | 2,198 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question about (double *)NULL

Umfpack is a C library for computations dealing with sparse
matrices. Several examples in the User's Guide use a certain
cast that puzzles me. Here is an example.

The prototype of the function umfpack_di_symb olic() is:

int umfpack_di_symb olic
(
int n_row,
int n_col,
const int Ap [ ],
const int Ai [ ],
const double Ax [ ],
void **Symbolic,
const double Control [UMFPACK_CONTROL],
double Info [UMFPACK_INFO]
);

The header file umfpack.h has:
#define UMFPACK_CONTROL 20

Here is a sample usage:

int main (void)
{
double *null = (double *) NULL ;
...
(void) umfpack_di_symb olic (n, n, Ap, Ai, Ax, &Symbolic, null, null) ;
...
return (0) ;
}

(Code fragments are put here by "cut-and-paste"ing from the manual.)

My question is: Does the cast in (double *)NULL accomplish anything?
It seems to me that the call to umfpack_di_symb olic() equivalent to:

umfpack_di_symb olic (n, n, Ap, Ai, Ax, &Symbolic, NULL, NULL) ;

Comments?

--
Rouben Rostamian
Apr 30 '06 #1
5 2835
Rouben Rostamian a écrit :
Umfpack is a C library for computations dealing with sparse
matrices. Several examples in the User's Guide use a certain
cast that puzzles me. Here is an example.

The prototype of the function umfpack_di_symb olic() is:

int umfpack_di_symb olic
(
int n_row,
int n_col,
const int Ap [ ],
const int Ai [ ],
const double Ax [ ],
void **Symbolic,
const double Control [UMFPACK_CONTROL],
double Info [UMFPACK_INFO]
);

The header file umfpack.h has:
#define UMFPACK_CONTROL 20

Here is a sample usage:

int main (void)
{
double *null = (double *) NULL ;
...
(void) umfpack_di_symb olic (n, n, Ap, Ai, Ax, &Symbolic, null, null) ;
...
return (0) ;
}

(Code fragments are put here by "cut-and-paste"ing from the manual.)

My question is: Does the cast in (double *)NULL accomplish anything?
It seems to me that the call to umfpack_di_symb olic() equivalent to:

umfpack_di_symb olic (n, n, Ap, Ai, Ax, &Symbolic, NULL, NULL) ;

Comments?


You are right. The only difference is that you waste code space in a
useless assignment, and that afterwards you write NULL in lowercase.

A
#define null NULL
would accomplish the same thing

Apr 30 '06 #2
Rouben Rostamian schrieb:
Umfpack is a C library for computations dealing with sparse
matrices. Several examples in the User's Guide use a certain
cast that puzzles me. Here is an example.

The prototype of the function umfpack_di_symb olic() is:

int umfpack_di_symb olic
(
int n_row,
int n_col,
const int Ap [ ],
const int Ai [ ],
const double Ax [ ],
void **Symbolic,
const double Control [UMFPACK_CONTROL],
double Info [UMFPACK_INFO]
);

The header file umfpack.h has:
#define UMFPACK_CONTROL 20

Here is a sample usage:

int main (void)
{
double *null = (double *) NULL ;
...
(void) umfpack_di_symb olic (n, n, Ap, Ai, Ax, &Symbolic, null, null) ;
...
return (0) ;
}

(Code fragments are put here by "cut-and-paste"ing from the manual.)

My question is: Does the cast in (double *)NULL accomplish anything?
It seems to me that the call to umfpack_di_symb olic() equivalent to:

umfpack_di_symb olic (n, n, Ap, Ai, Ax, &Symbolic, NULL, NULL) ;

Comments?


Educated guess:
It proactively shuts up a C++ compiler abused to compile C...

,---
$ cat doublecast.c
int main (void)
{
double *foo = (void *)0;

return 0;
}

$ gcc -std=c89 -pedantic -Wall -O doublecast.c -c
doublecast.c: In function `main':
doublecast.c:3: warning: unused variable `foo'

$ g++ -std=c++98 -pedantic -Wall -O doublecast.c -c
doublecast.c: In function `int main()':
doublecast.c:3: error: invalid conversion from `void*' to `double*'
doublecast.c:3: warning: unused variable 'foo'
`---
<OT>The correct C++ solution is to use "0" instead of "NULL".</OT>

As most library headers nowadays test whether C or C++ is the
language mode they are processed with, you usually have NULL
defined to be 0 for C++ and (void *)0 for C.
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Apr 30 '06 #3
On 2006-04-30, Rouben Rostamian <ro****@pc18.ma th.umbc.edu> wrote:
Umfpack is a C library for computations dealing with sparse
matrices. Several examples in the User's Guide use a certain
cast that puzzles me. Here is an example.

The prototype of the function umfpack_di_symb olic() is:

int umfpack_di_symb olic
(
int n_row,
int n_col,
const int Ap [ ],
const int Ai [ ],
const double Ax [ ],
void **Symbolic,
const double Control [UMFPACK_CONTROL],
double Info [UMFPACK_INFO]
);

The header file umfpack.h has:
#define UMFPACK_CONTROL 20

Here is a sample usage:

int main (void)
{
double *null = (double *) NULL ;
...
(void) umfpack_di_symb olic (n, n, Ap, Ai, Ax, &Symbolic, null, null) ;
...
return (0) ;
}

(Code fragments are put here by "cut-and-paste"ing from the manual.)

My question is: Does the cast in (double *)NULL accomplish anything?
It seems to me that the call to umfpack_di_symb olic() equivalent to:

umfpack_di_symb olic (n, n, Ap, Ai, Ax, &Symbolic, NULL, NULL) ;

Comments?


The cast is not needed in C (but is in C++).

If the package was originally written before C had function prototypes,
then the sample usage (with arguments of type double *) was needed for
compilers that used different representations for pointers to different
types. With function prototypes, the compiler, if necessary, converts
arguments with a value of NULL to the null pointer of the type of the
corresponding function parameter.
Apr 30 '06 #4
On Sun, 30 Apr 2006 17:28:50 -0000, "A. Bolmarcich"
<ag*****@earl-grey.cloud9.net > wrote in comp.lang.c:
On 2006-04-30, Rouben Rostamian <ro****@pc18.ma th.umbc.edu> wrote:
Umfpack is a C library for computations dealing with sparse
matrices. Several examples in the User's Guide use a certain
cast that puzzles me. Here is an example.

The prototype of the function umfpack_di_symb olic() is:

int umfpack_di_symb olic
(
int n_row,
int n_col,
const int Ap [ ],
const int Ai [ ],
const double Ax [ ],
void **Symbolic,
const double Control [UMFPACK_CONTROL],
double Info [UMFPACK_INFO]
);

The header file umfpack.h has:
#define UMFPACK_CONTROL 20

Here is a sample usage:

int main (void)
{
double *null = (double *) NULL ;
...
(void) umfpack_di_symb olic (n, n, Ap, Ai, Ax, &Symbolic, null, null) ;
...
return (0) ;
}

(Code fragments are put here by "cut-and-paste"ing from the manual.)

My question is: Does the cast in (double *)NULL accomplish anything?
It seems to me that the call to umfpack_di_symb olic() equivalent to:

umfpack_di_symb olic (n, n, Ap, Ai, Ax, &Symbolic, NULL, NULL) ;

Comments?


The cast is not needed in C (but is in C++).


No it is not.

<OT>
The C++ standard requires that the macro NULL be defined as an integer
constant expression that evaluates to a value of 0. It does not allow
it to be defined as such an expression cast to void *, as C does.
</OT>

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
May 1 '06 #5
Rouben Rostamian wrote:
Umfpack is a C library for computations dealing with sparse
matrices. Several examples in the User's Guide use a certain
cast that puzzles me. Here is an example.

The prototype of the function umfpack_di_symb olic() is:

int umfpack_di_symb olic
(
int n_row,
int n_col,
const int Ap [ ],
const int Ai [ ],
const double Ax [ ],
void **Symbolic,
const double Control [UMFPACK_CONTROL],
double Info [UMFPACK_INFO]
);

The header file umfpack.h has:
#define UMFPACK_CONTROL 20

Here is a sample usage:

int main (void)
{
double *null = (double *) NULL ;
...
(void) umfpack_di_symb olic (n, n, Ap, Ai, Ax, &Symbolic, null, null) ;
...
return (0) ;
}

My question is: Does the cast in (double *)NULL accomplish anything?
No.
It seems to me that the call to umfpack_di_symb olic() equivalent to:

umfpack_di_symb olic (n, n, Ap, Ai, Ax, &Symbolic, NULL, NULL) ;

Comments?


It's the same if umfpack_di_symb olic is actually prototyped before its
use.
If the function is not prototyped, then under C90 it will have an
implicit
declaration of...

int umfpack_di_symb olic();

The absense of a prototype would mean that NULL and (double *) NULL
might be different types and/or have different representations when
passed
as an argument. In either case, such a call would invoke undefined
behaviour.

With a prototype in scope the conversion from NULL to (double *) NULL
is implicit.

C99 removed implicit function declarations, but it did not add the
requirement
that a named function be prototyped before use.

Sensible programmers will turn on the 'require function prototypes'
option
on their compilers (if the compiler has one).

--
Peter

May 1 '06 #6

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

Similar topics

4
1300
by: pedicini | last post by:
I work with many dynamically allocated variables in my program including double **, int *, char *. For ex: double **d; d = new (double *) ; for(int i = 0; i < 10; i++) { d = new double; }
7
1643
by: Master of C++ | last post by:
Hello Folks, I have a programming dilemma with templates and "genericity". I can think of a few solutions, but I am not sure which one is the best in terms of genetic C++ style. Any suggestions will be greatly appreciated. I am writing a template class Polynomial that encapsulates the functionalities of a Polynomial. Here is a rough sketch for the class:
5
3298
by: PCHOME | last post by:
Hello! I am working on dividing a single C file into several files. Now I encounter a problem about the global variables and can not find a way to solve it. All global variables and codes used to be in that single file, that worked OK. But when I divdie that file into several ones, I have many "invalid use of undefined type" errors. The four files are main.c, main.h, readLP.h, and readLP.c. In readLP.h
7
2531
by: Peter Proost | last post by:
Hi, I'm creating an import module to read data from old textfiles, run some calculations on them and save them to sql server. I've figured out how to do a select on textfile using a schema.ini file (my textfile is delimeted by a | ) But I've got on problem remaining, below you can so two example rows out of the textfile: 560000||TS|alu dak|0000000067|P400|20|7101|401|0|0|0|0|||||N|J 560039||KM|"De Gaer":
7
3771
by: Mischa | last post by:
Hello, I am trying to use realloc multiple times to extend an array of doubles but unfortunatly it keeps failing. I think I am mixing up the size to which the old memory block needs to be extended. So if it's already 128 in size it needs to be realloc'd to (ORIGSIZE + NEWSIZE) right ? I have provided a small example below, maybe that will make my describtion somewhat clearer... Thank you for any suggestions..
2
1926
by: Rouben Rostamian | last post by:
The main() function in the following code defines an m by n matrix, assigns value(s) to its elements, then passes the matrix to function foo(). For whatever it's worth, I have declared foo() so as to make it treat its first argument as a "read-only" object, that is, foo() can read but not alter the matrix. I have a problem, however, with /calling/ foo. If I call foo as foo(a,m,n), my compiler (gcc) complains about:
5
3198
by: tjay | last post by:
Hi. I wrote some code using sprintf and atof to store a double as a string of fixed length and to convert it back to a double variable. The string is stored in a char buffer global variable. I'm afraid it might contain bugs though. If I serialize a double, I get a string of the format "-1.0000000000000000e+212". This string gets stored in the buffer. Then, to convert it back into a double, I pass it to the atof function. The problem...
0
1138
by: taquito | last post by:
I just started to learn C. This is a very simple question, so please forgive me for posting this here. I have a set of data in, let's say, .txt file. this txt file is in tab-delimited, like 1 4 9 2 6 10 3 7 11 4 8 12 Using fopen and while loop, I managed to print out the data line by line.
22
2763
by: Bill Reid | last post by:
I just noticed that my "improved" version of sscanf() doesn't assign floating point numbers properly if the variable assigned to is declared as a "float" rather than a "double". (This never cropped up before, since I rarely use "float"s for anything, and hardly ever use the function for floating-point numbers in the first place; I just was messing around testing it for all cases and noticed a problem.) Anyway, it is declared and I...
0
8676
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9029
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8898
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7734
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6524
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3051
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 we have to send another system
3
2006
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.