-1

I see some C++ syntax I am not familiar with:

fftfilt *mark_filt;
.
.
.
mark_filt = new fftfilt( ... ); // I left out arguments for the constructor.
.
.
.
mark_filt = (fftfilt *)0;
.

I do not understand what (fftfilt *)0 means or does? Perhaps someone who uses c++ all the time can explain this to me?

Thanks, Howard

Howard
  • 19
  • 1
  • 6
  • it's a pre-c++11 way of casting a null pointer to the correct type. – Richard Hodges Sep 30 '17 at 18:53
  • I wonder if it is the same thing as "mark_filt = NULL" ? – Howard Sep 30 '17 at 18:53
  • 1
    The cast is not necessary in C++, but it is in C. You can simply say: `mark_filt = 0;` - this used to be the preferred way of creating a null pointer, prior to C++11. –  Sep 30 '17 at 18:56
  • Start here: [The Definitive C++ Book Guide and List](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). – Jesper Juhl Sep 30 '17 at 19:04

2 Answers2

2

It's an old way to represent NULL, which is generally just a macro defined to be 0. You should instead prefer

mark_filt = nullptr;

although I hope before then since there was a new someone called delete mark_filt

Cory Kramer
  • 114,268
  • 16
  • 167
  • 218
0

The first comment is correct; it's a pre C++ 11 way of explicitly casting a null pointer to the correct type. And you are correct, it is equivalent to mark_filt = NULL;, sort of.

C++ performs implicit type promotion for various conversions, but these are limited. In the case of pointers, the pre C++ 11 way was to use NULL or (pointer_type *) cast. NULL itself has an implementation-specific definition and is implemented in different ways in the standard C++ headers (stdlib, I believe). Two common implementations of NULL are:

#define NULL 0
#define NULL ((void *)0)

The ramifications of these depend on compiler, but the second will fail if assigned to a non-pointer type. It will be implicitly cast to the correct type as it is not specifying the record Type that it is pointing to (ie. void is essentially a null type, void * is a pointer to null type, or an unspecified type).

In C++ 11 and above, it is more common to use mark_filt = nullptr, but this code would compile.

The MSDN site has some good documentation on this (no plug intended):

Andrew Myers
  • 2,754
  • 5
  • 32
  • 40
JimC
  • 69
  • 1
  • 7