What is the major reason for using void*?
When should we use void* for both input arguments and return value?
How can we cast the void* pointer to the type we need?
Thanx 26 2130
Janice wrote: What is the major reason for using void*?
Use a `void*' when you do not know the pointed-to
object's actual type, or do not care what it is, or
wish to conceal it.
When should we use void* for both input arguments and return value?
When both the arguments and the returned value meet
one or more of the criteria above.
How can we cast the void* pointer to the type we need?
The only way to cast anything is with a cast operator.
To convert a `void*' to an `int*', say, use `(int*)voidptr' .
Perhaps if you'd give a little more detail about what's
puzzling you, I'd be able to explain more clearly.
-- Er*********@sun .com
Eric Sosman <er*********@su n.com> writes: Janice wrote: How can we cast the void* pointer to the type we need?
The only way to cast anything is with a cast operator. To convert a `void*' to an `int*', say, use `(int*)voidptr' .
This is literally true, but not very helpful. It is not usually
necessary to cast to or from void * because conversions between
void * and other pointers to object or incomplete type do not
require casts.
--
"Large amounts of money tend to quench any scruples I might be having."
-- Stephan Wilms
Eric Sosman <er*********@su n.com> spoke thus: Perhaps if you'd give a little more detail about what's puzzling you, I'd be able to explain more clearly.
IMHO it sounds like homework, so maybe you did just fine...
--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
Ben Pfaff wrote: Eric Sosman <er*********@su n.com> writes:
Janice wrote:
How can we cast the void* pointer to the type we need?
The only way to cast anything is with a cast operator. To convert a `void*' to an `int*', say, use `(int*)voidptr' .
This is literally true, but not very helpful. It is not usually necessary to cast to or from void * because conversions between void * and other pointers to object or incomplete type do not require casts.
C'mon, Ben: Leave her professor *some* excuse for taking
off a mark or two, won't you?
Janice: If your questions aren't homework, I repeat my
offer to try to answer more clearly if you'll explain your
difficulty in greater detail. If they *are* homework, you
can find the answers to these and to all your other C questions
in "The Annotated ANSI C Standard" by Herbert Schildt.
-- Er*********@sun .com
Janice wrote: What is the major reason for using void*? When should we use void* for both input arguments and return value? How can we cast the void* pointer to the type we need?
Do your own homework.
Brian
Eric Sosman wrote: Ben Pfaff wrote:
Eric Sosman <er*********@su n.com> writes: Janice wrote:
How can we cast the void* pointer to the type we need?
The only way to cast anything is with a cast operator. To convert a `void*' to an `int*', say, use `(int*)voidptr' .
This is literally true, but not very helpful. It is not usually necessary to cast to or from void * because conversions between void * and other pointers to object or incomplete type do not require casts.
C'mon, Ben: Leave her professor *some* excuse for taking off a mark or two, won't you?
Janice: If your questions aren't homework, I repeat my offer to try to answer more clearly if you'll explain your difficulty in greater detail. If they *are* homework, you can find the answers to these and to all your other C questions in "The Annotated ANSI C Standard" by Herbert Schildt.
Ouch, that hurts ;-)
I would not have thought of homework...
On the other hand, even though [ni]{2}famous, Schildt's book
costs something. I suggest reviewing the chapters 4-6 of
this newsgroup's FAQ. Start from here: http://www.eskimo.com/~scs/C-faq/top.html
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Eric Sosman wrote: Janice wrote:
.... snip ... How can we cast the void* pointer to the type we need?
The only way to cast anything is with a cast operator. To convert a `void*' to an `int*', say, use `(int*)voidptr' .
Er - no cast needed nor desirable. Simply assign the void* to an
int* and the conversion is automatic.
--
Chuck F (cb********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!
In <I8********@new s.boeing.com> "Default User" <fi********@boe ing.com.invalid > writes: Janice wrote:
What is the major reason for using void*? When should we use void* for both input arguments and return value? How can we cast the void* pointer to the type we need?
Do your own homework.
If it's homework, it's the most stupid kind of homework I have ever seen.
These are the things that have to be taught to the student, rather than
asking him to figure them out by himself.
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Currently looking for a job in the European Union
In <41************ ***@yahoo.com> CBFalconer <cb********@yah oo.com> writes: Eric Sosman wrote: Janice wrote: ... snip ... How can we cast the void* pointer to the type we need?
The only way to cast anything is with a cast operator. To convert a `void*' to an `int*', say, use `(int*)voidptr' .
Er - no cast needed nor desirable. Simply assign the void* to an int* and the conversion is automatic.
At the expense of creating an additional object. Sometimes it is worth
it, but not always.
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Currently looking for a job in the European Union This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Kwan Ting |
last post by:
The_Sage, I see you've gotten yourself a twin asking for program in
comp.lang.c++ .
http://groups.google.co.uk/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&th=45cd1b289c71c33c&rnum=1
If you the oh so mighty programmer that you pretend to be, why don't you
just write some? (And oh, void main is still not allow by the C++ standard.)
Seeming as how you tried to quote the standard in an attempt to pretend
you're right, I'll quote the standard to once...
|
by: infobahn |
last post by:
printf("%p\n", (void *)0); /* UB, or not? Please explain your answer. */
|
by: sunglo |
last post by:
My doubt comes from trying to understand how thread return values work
(I know, it's off topic here), and I'm wondering about the meaning of
the "void **" parameter that pthread_join expects (I think this is
topical, since it's a C question, but please correct me and apologies
if I'm wrong).
I suppose that it's this way to allow for "generic" pointer
modification, but this implies dereferencing the "void **" pointer to
get a "void *"...
|
by: Twister |
last post by:
Hi All,
I have a question which might sound very basic.
I have a simple structure:
struct simple{
void *buffer;
};
typedef struct simple Simple;
|
by: Andreas Klimas |
last post by:
hello,
no many words, I will start with an example instead
int foo(void *r) {...}
void test(void) {
int *x=0;
foo(x); /* seems to me as valid */
}
| |
by: subramanian100in |
last post by:
I saw this question from www.brainbench.com
void *ptr;
myStruct myArray;
ptr = myArray;
Which of the following is the correct way to increment the variable
"ptr"?
Choice 1 ptr = ptr + sizeof(ptr);
|
by: Zero |
last post by:
Hello all,
I wonder about void?
To which category in the C programming language does it belong?
Of how many bits consits void?
Is it possible to define a varibale called
void a;
|
by: Barry |
last post by:
The problem brought by one earlier post from comp.lang.c++
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/bf636c48b84957b/
I take part of the question and reproduce the code to represent (partly)
the question.
#include <iostream>
template <class>
void f(...)
|
by: junky_fellow |
last post by:
Guys,
Consider a function
func(void **var)
{
/* In function I need to typecast the variable var as (int **)
I mean to say, I need to access var as (int **)
}
|
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...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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...
|
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,...
|
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...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |