473,779 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

passing the address of a pointer to a func that doesnt recieve a pointer-to-a-pointer

#include <stdio.h>
#include <stdlib.h>

//WARNING: The function's signature should be: f( int ** )
void f(int *ip) {
static int dummy = 5;
*ip = &dummy;
}

int main(){
int *ip;
f(&ip);
printf("%d",*ip );
return 0;
}

The function's signature should be: f( int ** ). However, f( int *) seems to
produce the same results, even though I am
warned by the compiler (Borland_bcc_5. 5):
Warning W8069 solution.c 5: Nonportable pointer conversion in function f
Warning W8075 solution.c 12: Suspicious pointer conversion in function main

What can go wrong when you pass the address of a pointer to a function that
does not recieve a pointer to a pointer?

TIA
jimjim
Mar 25 '06
16 3167
# The question was posted by "jimjim" <ne*****@blueyo nder.co.uk>.
# Please don't snip attributions. And *please* stop using your stupid
# '#' quoting character. You've been told repeatedly that it causes
# problems for some newsreaders; your stubbornness on this point is why
# I usually ignore anything you post.

Now I'm scared. Please, please, don't netkop me.

# Casting to suppress compiler warnings is dangerous and foolish.
# Parameters of different types can be passed by different mechanisms,
# even if they're the same size. For example, some systems might use
# different sets of registers for pointers vs. integers, or integers

If your compiler is incapable of moving values into correct registers
during a cast, you desperately need a new compiler.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
This is one wacky game show.
Mar 27 '06 #11
SM Ryan wrote:
The question was posted by "jimjim" <ne*****@blueyo nder.co.uk>.
Please don't snip attributions. And *please* stop using your stupid
'#' quoting character. You've been told repeatedly that it causes
problems for some newsreaders; your stubbornness on this point is why
I usually ignore anything you post.


Now I'm scared. Please, please, don't netkop me.
Casting to suppress compiler warnings is dangerous and foolish.
Parameters of different types can be passed by different mechanisms,
even if they're the same size. For example, some systems might use
different sets of registers for pointers vs. integers, or integers


If your compiler is incapable of moving values into correct registers
during a cast, you desperately need a new compiler.


The whole point of a cast is to force a compiler to do what you want it
to do, in which case it might very well end up storing values in
registers not suited for their types, and giving rise to undefined
behaviour. That is why it's advisable to use a cast only after
understanding the ramifications, (which might mean looking up
implementation specific behaviour), and when it's use is essential to
the code in question.

Mar 27 '06 #12
SM Ryan <wy*****@tang o-sierra-oscar-foxtrot-tango.fake.org> writes:
[...]
Casting to suppress compiler warnings is dangerous and foolish.
Parameters of different types can be passed by different mechanisms,
even if they're the same size. For example, some systems might use
different sets of registers for pointers vs. integers, or integers


If your compiler is incapable of moving values into correct registers
during a cast, you desperately need a new compiler.


Ok, the differences in parameter passing applies mostly in cases where
a call is performed with no prototype in scope.

The original code has a function that takes a parameter of type int*,
and calls it with an argument of type int**. The compiler quite
correctly complained (it's a constraint violation, so it's required to
do so).

The solution is to fix either the function or the call so the types
are consistent. Casting the int** argument to int* will (probably)
silence the warning, and won't cause problems with parameter passing
mechanisms. The only problem is that the result of converting the
int** value to int* is unlikely to be meaningful.

The OP asked what can go wrong; you advised him to hide the problem
with a meaningless cast.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mar 27 '06 #13

"SM Ryan" <wy*****@tang o-sierra-oscar-foxtrot-tango.fake.org> wrote in
message news:12******** *****@corp.supe rnews.com...
# The question was posted by "jimjim" <ne*****@blueyo nder.co.uk>.
# Please don't snip attributions. And *please* stop using your stupid
# '#' quoting character. You've been told repeatedly that it causes
# problems for some newsreaders; your stubbornness on this point is why
# I usually ignore anything you post.

Now I'm scared. Please, please, don't netkop me.


Keith. How can you criticize him for "#" when you use "]" on occasion?
Mar 27 '06 #14
"Rod Pemberton" <do*********@so rry.bitbuck.cmm > writes:
"SM Ryan" <wy*****@tang o-sierra-oscar-foxtrot-tango.fake.org> wrote in
message news:12******** *****@corp.supe rnews.com...
# The question was posted by "jimjim" <ne*****@blueyo nder.co.uk>.
# Please don't snip attributions. And *please* stop using your stupid
# '#' quoting character. You've been told repeatedly that it causes
# problems for some newsreaders; your stubbornness on this point is why
# I usually ignore anything you post.

Now I'm scared. Please, please, don't netkop me.


Keith. How can you criticize him for "#" when you use "]" on occasion?


I use "]" only when I'm quoting something that doesn't come directly
from the parent article; using ">" in that context could be
misleading. I've never heard of any newsreader having problems with
"]" (if you know of one that does, please let me know). Multiple
people have said that "#" does cause problems. It can be argued that
that's a bug in those newsreaders, but I see no point in deliberately
and repeatedly triggering that bug. (In my own newsreader, it's not
much of a problem, except that the command to re-fill a paragraph
doesn't recognize a leading "#" as a quoting character; it does
recognize both ">" and "]".)

SM Ryan has been asked repeatedly why he insists on using "#"; he has
never answered. I can only assume he's being deliberately obnoxious,
which is why I usually ignore him. (I usually try to ignore you as
well, but this was actually a reasonable question.)

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mar 27 '06 #15
On Mon, 27 Mar 2006 20:33:34 GMT, in comp.lang.c , Keith Thompson
<ks***@mib.or g> wrote:
SM Ryan has been asked repeatedly why he insists on using "#"; he has
never answered.


Actually, I recall that he did. He said at one point that he'd written
his own newsreader and deliberately designed it to use this character
for quotes for an unknown reason. When challenged, he got stroppy and
said everyone else's s/w was broken. Go figure...

Mark McIntyre
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Mar 27 '06 #16
On 2006-03-27, Keith Thompson <ks***@mib.or g> wrote:
"Rod Pemberton" <do*********@so rry.bitbuck.cmm > writes:
"SM Ryan" <wy*****@tang o-sierra-oscar-foxtrot-tango.fake.org> wrote in
message news:12******** *****@corp.supe rnews.com...
# The question was posted by "jimjim" <ne*****@blueyo nder.co.uk>.
# Please don't snip attributions. And *please* stop using your stupid
# '#' quoting character. You've been told repeatedly that it causes
# problems for some newsreaders; your stubbornness on this point is why
# I usually ignore anything you post.

Now I'm scared. Please, please, don't netkop me.
Keith. How can you criticize him for "#" when you use "]" on occasion?


I use "]" only when I'm quoting something that doesn't come directly
from the parent article;


I use | for that purpose, it works better in my newsreader.
using ">" in that context could be misleading. I've never heard of
any newsreader having problems with "]" (if you know of one that does,
please let me know).
My editor doesn't allow me to easily reflow text with quote markers
other than > and # by default. However, I have altered the default
setting, and I may alter it further.
Multiple people have said that "#" does cause problems. It can be
argued that that's a bug in those newsreaders, but I see no point in
deliberately and repeatedly triggering that bug.
Which newsreaders are those? Mine doesn't color either # or ] properly,
but I could change that if i cared. oddly, it recognizes = as a quote
marker.
(In my own newsreader, it's not much of a problem, except that the
command to re-fill a paragraph doesn't recognize a leading "#" as
a quoting character; it does recognize both ">" and "]".) SM Ryan has been asked repeatedly why he insists on using "#"; he has
never answered. I can only assume he's being deliberately obnoxious,
which is why I usually ignore him. (I usually try to ignore you as
well, but this was actually a reasonable question.)


What _does_ it break? It's hard to imagine what that could break, other
than people whining that it doesn't format it as a blockquote in their
gui newsreaders. Do non-quoted lines beginning in # also break them? in
that case, how does it know the difference? What i'm saying is, does it
actually _break_ them, or does it somehow fail to be recognized as
quoted text, and if the latter, is that really worth caring about?

If the newsreader really breakes, like, crashes, or fails to display, on
lines beginning in #, that is a serious bug in the newsreader and there
are much more serious problems than people using it as a quote marker.
If it just doesn't format it or color it or do other special things
based on it being quoted text, that's not really worth giving a crap
about IMO.
Mar 27 '06 #17

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

Similar topics

5
9377
by: Newsgroup - Ann | last post by:
Gurus, I have the following implementation of a member function: class A { // ... virtual double func(double v); void caller(int i, int j, double (* callee)(double)); void foo() {caller(1, 2, func);
9
5298
by: Juggernaut | last post by:
I am trying to create a p_thread pthread_create(&threads, &attr, Teste, (void *)var); where var is a char variable. But this doesnt't work, I get this message: test.c:58: warning: cast to pointer from integer of different size. Now I thought that when it was a void I could pass anything? Thing is it works when I use an int, but in this case I wanted to use a char. It wouldnt be hard to work around it, but it annoys me because I've heard...
17
3604
by: Charles Sullivan | last post by:
The library function 'qsort' is declared thus: void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *)); If in my code I write: int cmp_fcn(...); int (*fcmp)() = &cmp_fcn; qsort(..., fcmp); then everything works. But if instead I code qsort as:
3
5997
by: kevin | last post by:
This is a repost with an update Does any one know how to pass a function pointer as a function parameter from VB .NET to a C dll? Currently I'm passing it this way Public Delegate Sub DSCUserInterruptFunction()
2
2228
by: mark.e.nelson | last post by:
Hi, I am trying to pass a pointer to a struct to a function that uses the data in the struct, and also happens to use ncurses. I always get a segmentation violation when the program exits. I have experimented with passing a pointer to a struct as an argument to a function that does not use ncurses and that seems to work fine. Can anyone provide any advice? I apologise if this is the wrong place to ask - I am just coming back to C...
15
4663
by: mangesh | last post by:
This code is from c++ faq in section 11 : void someCode() { char memory; void* p = memory; Fred* f = new(p) Fred(); f->~Fred(); // Explicitly call the destructor for the placed object }
5
2409
by: mshaaban | last post by:
Hello, In my code I have a large static 2D arrays defined as: code: #define LONMAX 1440 #define LATMAX60 480 void main (int argc, char *argv)
0
1401
by: Philip Semanchuk | last post by:
On Oct 22, 2008, at 8:33 PM, Robert Kern wrote: I agree. To deny users of this module access to this param of shmat() would be design arrogance on my part. To do so would be to claim that I know better than everyone who might want to use my module. Using values other than NULL might be unwise (the man page I'm looking at states that clearly) but isn't one of the core design philosophies of Python "we're all consenting adults"?
5
1833
by: miner | last post by:
Hi all I'm doing my first steps in C and I need some help plz. I have 2 structs, a node* and a stack*. I want to write a push() function that accepts to arguments, the node to insert and the pointer to the the top of the stack. This way it works without problems: push(node *theNode, stack *theStack) The call looks like that: push(newNode, newStack) and inside the function I can access the pointer with newStack->head. I tried doing...
0
9636
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, 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...
0
9474
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10306
Oralloy
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...
0
10138
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 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...
1
10074
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,...
0
9930
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 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...
1
7485
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 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...
0
5373
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...
1
4037
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 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.