473,405 Members | 2,272 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

void and this

Hello,

I have a class member function declared as

class some_class {
....
virtual int call(void);
};

Can I use this-> inside the function body?
Thanks.

Vladimir
Jul 19 '05
52 6230
Dave Vandervies wrote:
E. Robert Tisdale wrote:
Dave Vandervies wrote:
Gavin Deane wrote:

not do that. Doesn't C99 have a built in boolean type now?

C99 has a built in boolean type (_Bool), as well as a standard header
(<stdbool.h>) that defines macros for bool, true, and false.

Since in practice you're unlikely to be able to avoid having to coexist
with C90 for quite some time, this doesn't make it any easier to use
bool in headers that have to be both C- and C++-clean.
It's probably still best to use int and document that
the value represents a boolean value for that.


This is *bad* advice.

C90 programmers should provide their own stdbool.h header file:

#ifndef guard_stdbool_h
#define guard_stdbool_h 1
typedef int bool;
const int false = 0;
const int true = !false;
#endif/*guard_stdbool_h */

And how does this make it easier to have headers that can be used with
C90, C99, *and* C++?
Unless there are constraints on C++'s bool that I'm not aware of, it
would be reasonable to expect C++'s bool and C99's _Bool to be the same
type for a compiler that supports both languages. Expecting this to
be the same as int is less reasonable, and without all three being the
same it becomes pointless to use "bool" in headers that are intended to
be used between the languages.

Do you have an alternate suggestion for being able to put this in a
header file:
--------
void do_something_with_boolean_value(bool);
--------
and being able to correctly call do_something_with_boolean_value from
any of the three languages?
Aside from interoperability issues that can be confined to header files,
C90 programmers should write in C90, which doesn't include a boolean type
(though it does allow one to be created if it's desired, and with care
the semantics of such a type (if not the representation) can be made
compatible with those of the bool from C99's <stdbool.h>).


You are confusing interoperability with portability.
None of the ANSI/ISO C and C++ standards guarantee interoperability.
There in *no* guarantee that you can link in object files
created by any other C or C++ compiler
and get the code to run correctly.

Portability guarantees *only* that you can compile and link together
object files created by the same compiler.
Programmers who have only a C90 compiler should provide
or should be provided with an stdbool.h header file
like the one shown above, include it in their programs
and use the bool type and the false and true constants.

Programmers who have a C99 compiler will use the stdbool.h header file
that came with their compiler.

Programmers who have a C++ compiler
must provide an empty stdbool.h header file
and the compiler will use the built-in type bool.

Jul 19 '05 #51

Just to resurrect an old old thread, since this same thread came
up at work just recently and now I wish to spark more discussion.
Jonathan Mcdougall wrote:
int f();

could not be more explicit.
David B. Held wrote:
Sure it could. Add "void".

Rolf Magnus wrote:
How does adding a pseudo parameter of type void make it more expicit
that you want no parameters?


The question that came up in my mind is that this "pseudo
parameter" isn't pseudo at all. It means, quite explicitly, that
the function takes no parameters.

While I understand that empty parentheses means "takes no
parameters," doesn't this beg the question (compatibility with
the first C aside) of why a function that takes no parameters
needs to have 'void' stated as its return type? I mean, if we're
trying to get rid of useless typing, certainly a function that
returns nothing (indeed, a function that doesn't even have an
explicit return statement) shouldn't need to specify that it
returns nothing- it could just get away with not stating that it
returns something.

To pull it all together, putting void in the parameters list is
only as silly (IMO) as putting void as the return type. Alas, I
still don't use void between the parens, but now see a lack of
symmetry in the way type specifiers are used.

Does my logic fail, besides contradicting The Almighty Standard?
-tom!
Jul 22 '05 #52

"Tom Plunket" <to***@fancy.org> skrev i en meddelelse
news:lm********************************@4ax.com...

Just to resurrect an old old thread, since this same thread came
up at work just recently and now I wish to spark more discussion.
[snip]
While I understand that empty parentheses means "takes no
parameters," doesn't this beg the question (compatibility with
the first C aside) of why a function that takes no parameters
needs to have 'void' stated as its return type? I mean, if we're
trying to get rid of useless typing, certainly a function that
returns nothing (indeed, a function that doesn't even have an
explicit return statement) shouldn't need to specify that it
returns nothing- it could just get away with not stating that it
returns something.
For historical reasons, a function that did not specify a return type was
assumed to return int. This is not the case in C++ and probably not in C
eiter.

To pull it all together, putting void in the parameters list is
only as silly (IMO) as putting void as the return type. Alas, I
still don't use void between the parens, but now see a lack of
symmetry in the way type specifiers are used.

Does my logic fail, besides contradicting The Almighty Standard?
You could easily imagine a language where no return-type was equivalent to a
void return. Forgetting your inheritance is not a good thing, however.


-tom!

Kind regards
Peter
Jul 22 '05 #53

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

Similar topics

9
by: Pushker Pradhan | last post by:
I've a function which accepts void * as the arg because the actual datatype can be char or float or anything. The fuction: void convolve(void *x, float *convx, uint32 numrowsx, uint32 numcolsx,...
15
by: Stig Brautaset | last post by:
Hi group, I'm playing with a little generic linked list/stack library, and have a little problem with the interface of the pop() function. If I used a struct like this it would be simple: ...
14
by: Enrico `Trippo' Porreca | last post by:
Given: typedef struct Node Node; struct Node { void *obj; Node *next; }; typedef struct Stack Stack; struct Stack {
3
by: Jason luo | last post by:
Hi all, In c99-standard page 52,there is a sentence about void,as below: If an expression of any other type is evaluated as a void expression, its value or designator is discarded. I don't...
5
by: noblesantosh | last post by:
Hi all, What is the difference between following two function definations? <1> void func(void) { /* some code */ } <2> void func()
3
by: cees | last post by:
Hi, I need to call an external C-function that accept an array of void pointers (void **). Each item can either be a single float,int,char or a C-array of these types. Is that possible and if so...
5
by: Niu Xiao | last post by:
I saw a lot of codes like: void foo(void* arg) void bar(void** arg) f((void*)p) but what does void pointer mean in c? I just know it stands for generic pointer. thanks.
18
by: Giannis Papadopoulos | last post by:
According to the standard (ISO C99 draft WG14/N1124), void is the incomplete type that cannot be completed and comprises the empty set of values. Since it declares the absense of a value can it be...
5
by: Gary Wessle | last post by:
I am getting task.cpp:109: error: argument of type 'void (Spac_task::)()' does not match 'void* (*)(void*)' when trying to execute the line int thr_id = pthread_create(&p_thread, NULL,...
4
by: brianhray | last post by:
Hello: I am writing a C interface and was curious how/why a void* can be used as a reference parameter. //////////////////////////////////////////////////////////// // WORKS: // Client1.h...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
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
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
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...

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.