473,395 Members | 1,383 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,395 software developers and data experts.

Calling static function using uninitialized pointer??

Is the following code reliable? I'm wondering whether it is valid to
invoke the static function using uninitialized pointer.

-----------------
#include <iostream>

class staticCl
{
public:
static void display()
{
}

} ;

int main()
{
staticCl* ptr ;
ptr->display() ;

}
-----------------

Jan 17 '06 #1
4 2072
qa********@rediffmail.com wrote:
Is the following code reliable? I'm wondering whether it is valid to
invoke the static function using uninitialized pointer.

A static member isn't called using the pointer. What you have is
undefined behaviour.
--
Ian Collins.
Jan 17 '06 #2
Hi

qa********@rediffmail.com wrote:
Is the following code reliable? I'm wondering whether it is valid to
invoke the static function using uninitialized pointer. staticCl* ptr ;
ptr->display() ;


The expression is equivalent to "(*ptr).display()", so you invoke undefined
behavior by dereferencing ptr.

Markus
Jan 17 '06 #3
> A static member isn't called using the pointer. What you have is
undefined behaviour.


Right. The code may work with most compilers but you can not rely on
that.

Just to clarify: Call your method staticCl::display() ...

--
Henryk

Jan 17 '06 #4
qa********@rediffmail.com wrote:
Is the following code reliable? I'm wondering whether it is valid to
invoke the static function using uninitialized pointer.

-----------------
#include <iostream>

class staticCl
{
public:
static void display()
{
}

} ;

int main()
{
staticCl* ptr ;
ptr->display() ;

}
-----------------


Undefined behaviour. Why not use staticCl::display() ?

Jan 17 '06 #5

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

Similar topics

2
by: Bj?rn Toft Madsen | last post by:
Hi all, The network library I use communicates with my app using a callback function. This callback function is called with the type of message, a void pointer to he actual message and a user...
2
by: William Payne | last post by:
Hello, consider these following two classes. A base class, class MDIChildWindow, and a class inherting from that base class, class Document. In the static base member function callback() I obtain a...
4
by: marvind | last post by:
I think I am running into the static initialization problem but I do not understand why. I am trying to parse a configuration file. To make this parser generic I register callbacks for various...
19
by: Ross A. Finlayson | last post by:
Hi, I hope you can help me understand the varargs facility. Say I am programming in ISO C including stdarg.h and I declare a function as so: void log_printf(const char* logfilename, const...
12
by: confusedcoder | last post by:
Suppose I have the following function: void doSomething(char** array, int size); Normally, I would call the function with an array of, say, 3 elements... char* strs = { "str1","str2","str3"...
15
by: Charles Sullivan | last post by:
Assume I have a static array of structures the elements of which could be any conceivable mixture of C types, pointers, arrays. And this array is uninitialized at program startup. If later in...
3
by: Webdiyer | last post by:
I want to integrate SecurID two-factor authentication system of the RSASecurity.inc into our asp.net application,but I get into trouble when trying to call the API functions of the ACE Agent,I got...
13
by: santosh | last post by:
Hi, If I call free() with a uninitialised pointer, will the program state become undefined, or will free() return harmlessly? Incidentally, is there a way in Standard C to determine weather a...
17
by: copx | last post by:
I don't know what to think of the following.. (from the dietlibc FAQ) Q: I see lots of uninitialized variables, like "static int foo;". What gives? A: "static" global variables are initialized...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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:
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...

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.