Hi all,
Does a "NULL constant function" exist in C? I mean:
I am searching for a C language constant which would be something like
a function but which would be translated by a compiler into "nothing":
no argument push in the stack pointer, no execution of the function
instructions, no cleaning up, nothing, nada, rien, vide...
I could then initialize a function pointer f to that constant function
and ask
(*f)(any_argume nt_list)
and the compiler would translate it and write in the text section:
*NOTHING*
I apologize if it seems "pathetical ly useless" but actually I would
find it the right tool to perform, for example,
(*MyVector->methods->NormalizeVecto r)(MyVector->info) if I know
MyVector is unit-length (so that it would not be modified by the
NormalizeVector function).
To perform the normalization is useless, time consuming and I am
exposed to rounding errors.
Any input appreciated
Thomas 7 4937
In <7d************ *************@p osting.google.c om> th************* @jrc.it (Thomas L.) writes: Does a "NULL constant function" exist in C? I mean: I am searching for a C language constant which would be something like a function but which would be translated by a compiler into "nothing": no argument push in the stack pointer, no execution of the function instructions , no cleaning up, nothing, nada, rien, vide...
I could then initialize a function pointer f to that constant function and ask (*f)(any_argum ent_list) and the compiler would translate it and write in the text section:
*NOTHING*
There is no such thing and you can't even use something like
void null(void) {}
for this purpose, because calling this function with a non-empty argument
list invokes undefined behaviour.
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de th************* @jrc.it (Thomas L.) writes: Does a "NULL constant function" exist in C? I mean:
There's the null pointer constant. It's expressed as "0".
I am searching for a C language constant which would be something like a function but which would be translated by a compiler into "nothing": no argument push in the stack pointer, no execution of the function instructions, no cleaning up, nothing, nada, rien, vide...
I could then initialize a function pointer f to that constant function and ask (*f)(any_argume nt_list) and the compiler would translate it and write in the text section:
*NOTHING*
That's not what a null function pointer does. Instead,
invoking it yields undefined behavior. But you could get similar
behavior by testing whether the pointer is non-null:
if (f)
f(args);
--
"Welcome to the wonderful world of undefined behavior, where the demons
are nasal and the DeathStation users are nervous." --Daniel Fox
"Dan Pop" <Da*****@cern.c h> wrote in message
news:cd******** **@sunnews.cern .ch... There is no such thing and you can't even use something like
void null(void) {}
What about
void null(...) { }
Is that valid C?
Dave
"Dave" <vd*****@freema il.hu> writes: void null(...) { }
Is that valid C?
No, varargs functions must have at least one fixed argument.
Otherwise what would you specify as the second argument to
va_start()?
Besides that, varargs functions are not compatible with
non-varargs functions.
--
Ben Pfaff
email: bl*@cs.stanford .edu
web: http://benpfaff.org
Ben Pfaff <bl*@cs.stanfor d.edu> wrote in message news:<87******* *****@benpfaff. org>... That's not what a null function pointer does. Instead, invoking it yields undefined behavior. But you could get similar behavior by testing whether the pointer is non-null: if (f) f(args);
Yes, sure.
But it's perhaps even less costy to point my pointer function with a
void *f(argument_lis t){}? (Perhaps some compilers can optimize this to
*noting*) There is compile-time type-checking, at run-time the passing
of argument on the stack is there, and I find it more "clean".
Dave wrote: "Dan Pop" <Da*****@cern.c h> wrote in message news:cd******** **@sunnews.cern .ch...
There is no such thing and you can't even use something like
void null(void) {}
What about void null(...) { }
Is that valid C?
Dave
Don't think so. What about void null(void) { NULL; } ?
Dan This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: junky_fellow |
last post by:
Can 0x0 be a valid virtual address in the address space
of an application ?
If it is valid, then the location pointed by a NULL pointer
is also valid and application should not receive "SIGSEGV"
( i am talking of unix machine ) while trying to read that
location.
Then how can i distinguish between a NULL pointer and an invalid
location ?
Is this essential that NULL pointer should not point to any of
the location in the virtual address...
|
by: Jason Curl |
last post by:
I've been reading this newsgroup for some time and now I am thoroughly
confused over what NULL means.
I've read a NULL pointer is zero (or zero typecast as a void pointer),
others say it's compiler dependent (and that NULL might be anything, but
it is always NULL).
The source snippet is below. The question is:
- When I use calloc to allocate a block of memory, preinitialising it to
zero, is this equivalent (and portable C) to...
|
by: Alexei A. Frounze |
last post by:
Seems like, to make sure that a pointer doesn't point to an object/function,
NULL (or simply 0) is good enough for both kind of pointers, data pointers
and function pointers as per 6.3.2.3:
3 An integer constant expression with the value 0, or such an expression
cast to type void *, is called a null pointer constant.55)
If a null pointer constant is converted to a pointer type, the resulting
pointer, called a null pointer, is guaranteed...
|
by: yossi.kreinin |
last post by:
Hi!
There is a system where 0x0 is a valid address, but 0xffffffff isn't.
How can null pointers be treated by a compiler (besides the typical
"solution" of still using 0x0 for "null")?
- AFAIK C allows "null pointers" to be represented differently then
"all bits 0". Is this correct?
- AFAIK I can't `#define NULL 0x10000' since `void* p=0;' should work
just like `void* p=NULL'. Is this correct?
|
by: Sheldon |
last post by:
Hi,
This program works when tested with gdb ( see results 1) but when used
in a larger program where 12 becomes 1500 there exists a problem when
freeing the memory ( see results 2). Can anyone give any advise here?
--------------------------------------------------
#include <stdlib.h>
#include <stdio.h>
int main(void) {
| |
by: sam_cit |
last post by:
Hi Everyone,
I tried the following program unit in Microsoft Visual c++ 6.0 and the
program caused unexpected behavior,
#include <stdio.h>
#include <string.h>
int main()
{
|
by: lovecreatesbea... |
last post by:
Do you prefer malloc or calloc?
p = malloc(size);
Which of the following two is right to get same storage same as the
above call?
p = calloc(1, size);
p = calloc(size, 1);
|
by: lak |
last post by:
What is the difference b/w '\0' and NULL?
In which case It is useful?
|
by: polas |
last post by:
Afternoon all,
I have some code (which I thought was OK, but now appreciate is
probably not by the standard) which contains
int a;
......
if (a==NULL)
{
....
|
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: 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: 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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
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...
| |