473,587 Members | 2,230 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

fmemopen: assignment makes pointer from integer without a cast

The following if condition

if((stream = fmemopen((void* )str, strlen(str), "r")) == NULL){
// ...
}
gives me a warning: assignment makes pointer from integer without a
cast

But only when I compile it with gcc. With g++ it's fine. Why does the
warning show up and how can I get rid of it (using gcc)?

I tried it with gcc 3.2.2 and 3.3.1 and got the same warnings both
times.

Thanks!
Markus
PS: Here is a mini version of a program I am trying

#include <stdio.h>
#include <string.h>

int main(){
char ch;
FILE *stream;
char *str = "test";
if((stream = fmemopen((void* )str, strlen(str), "r")) == NULL){
fprintf(stderr, "Cannot open stream to string '%s'\n", str);
}
while ((ch = fgetc (stream)) != EOF)
printf ("Got %c\n", ch);
fclose (stream);
return 0;
}
Nov 14 '05 #1
14 4059
Markus Dehmann wrote:
The following if condition

if((stream = fmemopen((void* )str, strlen(str), "r")) == NULL){
// ...
}
gives me a warning: assignment makes pointer from integer without a
cast
Since no fmem* function exists as part of standard C or even C++, you
need to ask in a newsgroup, mailing list, or tech support for your
implementation. ..
But only when I compile it with gcc. With g++ it's fine. Why does the
warning show up and how can I get rid of it (using gcc)?
.... and there are current gcc implementations delivered without any
fmem* functions as part of the supplied libraries.

It appears that you have not included the appropriate prototypes for
your function. If you have invoked gcc as a c89 or c99 compliant
compiler then it is certain that the headers you included
#include <stdio.h>
#include <string.h>


have no prototypes for any fmem* functions visible.
Nov 14 '05 #2
Markus Dehmann wrote:

The following if condition

if((stream = fmemopen((void* )str, strlen(str), "r")) == NULL){
// ...
}
gives me a warning: assignment makes pointer from integer without
a cast .... snip ...
#include <stdio.h>
#include <string.h>

int main(){
char ch;
FILE *stream;
char *str = "test";
if((stream = fmemopen((void* )str, strlen(str), "r")) == NULL){
fprintf(stderr, "Cannot open stream to string '%s'\n", str);
}
while ((ch = fgetc (stream)) != EOF)
printf ("Got %c\n", ch);
fclose (stream);
return 0;
}


There is no such standard function as fmemopen. Even if there
were and you have simply neglected to #include the appropriate
header, and the function took a void* first parameter, you should
not be casting anything. So your code should really read:

#include <stdio.h>
#include <string.h>
#include "fmemopen.h "

int main(void) {
char ch;
FILE *stream;
char *str = "test";

if (!(stream = fmemopen(str, strlen(str), "r"))) {
fprintf(stderr, "Cannot open stream to string '%s'\n",
str);
}
else {
while ((ch = fgetc(stream)) != EOF)
printf("Got %c\n", ch);
fclose(stream);
}
return 0;
}

assuming fmemopen.h declares:

FILE *fmemopen(void *, size_t, char *);

In addition, names begining with "str" are reserved for the
implementation. You should change those.

--
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!
Nov 14 '05 #3

"CBFalconer " <cb********@yah oo.com> wrote in message news:40******** *******@yahoo.c om...
Markus Dehmann wrote: [..]
assuming fmemopen.h declares:

FILE *fmemopen(void *, size_t, char *);

In addition, names begining with "str" are reserved for the
implementation. You should change those.

IIRC, the restriction is not for the local variables. Please
correct me, if I understood it wrongly.

Vijay
--
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!

Nov 14 '05 #4
In <40************ ***@yahoo.com> CBFalconer <cb********@yah oo.com> writes:
Markus Dehmann wrote:

The following if condition

if((stream = fmemopen((void* )str, strlen(str), "r")) == NULL){
// ...
}
gives me a warning: assignment makes pointer from integer without
a cast... snip ...

#include <stdio.h>
#include <string.h>

int main(){
char ch;
FILE *stream;
char *str = "test";
if((stream = fmemopen((void* )str, strlen(str), "r")) == NULL){
fprintf(stderr, "Cannot open stream to string '%s'\n", str);
}
while ((ch = fgetc (stream)) != EOF)
printf ("Got %c\n", ch);
fclose (stream);
return 0;
}


....In addition, names begining with "str" are reserved for the
implementation . You should change those.


A little knowledge is a dangerous thing. If you can't be bothered to
learn the full rule (or it exceeds your learning capabilities) it is OK
if you use the simplified version above for *your own* purposes. It is,
however, sheer stupidity to try to impose it to others, who may be capable
of learning the full rule and, therefore, have no use for your simplified
version.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #5
"Vijay Kumar R Zanvar" <vi*****@global edgesoft.com> wrote in message
news:2k******** *****@uni-berlin.de...
"CBFalconer " <cb********@yah oo.com> wrote in message news:40******** *******@yahoo.c om...

In addition, names begining with "str" are reserved for the
implementation. You should change those.


IIRC, the restriction is not for the local variables. Please
correct me, if I understood it wrongly.


See 7.1.3, 7.1.4 & 7.26

Identifiers beginning with 'str' followed by at least one lower case letter are reserved
for use as identifiers with external linkage. [In C90, such linkage is possibly case
insensitive.] If <string.h> or <stdlib.h> is included, then they are reserved as macro
names and file scope identifiers too.

But it's still possible to declare a local (auto) variable and have problems...

#include <string.h>

void bar(int);

void foo(void)
{
void (*strobe)(int) = bar; /* ok */
strobe(42); /* UB */
}

--
Peter
Nov 14 '05 #6
On Sat, 26 Jun 2004 12:38:41 +1000, "Peter Nilsson"
<ai***@acay.com .au> wrote in comp.lang.c:
"Vijay Kumar R Zanvar" <vi*****@global edgesoft.com> wrote in message
news:2k******** *****@uni-berlin.de...
"CBFalconer " <cb********@yah oo.com> wrote in message news:40******** *******@yahoo.c om...

In addition, names begining with "str" are reserved for the
implementation. You should change those.


IIRC, the restriction is not for the local variables. Please
correct me, if I understood it wrongly.


See 7.1.3, 7.1.4 & 7.26

Identifiers beginning with 'str' followed by at least one lower case letter are reserved
for use as identifiers with external linkage. [In C90, such linkage is possibly case
insensitive.] If <string.h> or <stdlib.h> is included, then they are reserved as macro
names and file scope identifiers too.

But it's still possible to declare a local (auto) variable and have problems...

#include <string.h>

void bar(int);

void foo(void)
{
void (*strobe)(int) = bar; /* ok */
strobe(42); /* UB */
}


I disagree with your assessment. The fact that a block scoped pointer
object holds the name of something (function or object) with external
linkage does not violate the standard requirement above. The linkage
and scope that count are only that of the identifier itself, 'strobe'
in this case.

There is absolutely no undefined behavior in your example.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 14 '05 #7
"Jack Klein" <ja*******@spam cop.net> wrote in message
news:cm******** *************** *********@4ax.c om...

On Sat, 26 Jun 2004 12:38:41 +1000, "Peter Nilsson"
<ai***@acay.com .au> wrote in comp.lang.c:
"Vijay Kumar R Zanvar" <vi*****@global edgesoft.com> wrote in message
news:2k******** *****@uni-berlin.de...

"CBFalconer " <cb********@yah oo.com> wrote in message
news:40******** *******@yahoo.c om...
>
> In addition, names begining with "str" are reserved for the
> implementation. You should change those.
>

IIRC, the restriction is not for the local variables. Please
correct me, if I understood it wrongly.


See 7.1.3, 7.1.4 & 7.26

Identifiers beginning with 'str' followed by at least one lower
case letter are reserved for use as identifiers with external
linkage. [In C90, such linkage is possibly case insensitive.]
If <string.h> or <stdlib.h> is included, then they are reserved ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^ as macro names and file scope identifiers too. ^^^^^^^^^^^^^^
But it's still possible to declare a local (auto) variable and have
problems...

#include <string.h>

void bar(int);

void foo(void)
{
void (*strobe)(int) = bar; /* ok */
strobe(42); /* UB */
This is a function macro like application of a reserved identifier.
}


I disagree with your assessment. The fact that a block scoped pointer
object holds the name of something (function or object) with external
linkage does not violate the standard requirement above. ...


It's the reserved use as a function macro which is the problem.

--
Peter
Nov 14 '05 #8
"Peter Nilsson" <ai***@acay.com .au> wrote:
"Jack Klein" <ja*******@spam cop.net> wrote in message
news:cm******* *************** **********@4ax. com...

On Sat, 26 Jun 2004 12:38:41 +1000, "Peter Nilsson"
<ai***@acay.com .au> wrote in comp.lang.c:
> "Vijay Kumar R Zanvar" <vi*****@global edgesoft.com> wrote in message
> news:2k******** *****@uni-berlin.de...
> >
> > "CBFalconer " <cb********@yah oo.com> wrote in message
> > news:40******** *******@yahoo.c om...
> > >
> > > In addition, names begining with "str" are reserved for the
> > > implementation. You should change those.
> >
> > IIRC, the restriction is not for the local variables. Please
> > correct me, if I understood it wrongly.
>
> See 7.1.3, 7.1.4 & 7.26
>
> Identifiers beginning with 'str' followed by at least one lower
> case letter are reserved for use as identifiers with external
> linkage. [In C90, such linkage is possibly case insensitive.]
> If <string.h> or <stdlib.h> is included, then they are reserved ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^ > as macro names and file scope identifiers too. ^^^^^^^^^^^^^^ >
> But it's still possible to declare a local (auto) variable and have
> problems...
>
> #include <string.h>
>
> void bar(int);
>
> void foo(void)
> {
> void (*strobe)(int) = bar; /* ok */
> strobe(42); /* UB */
This is a function macro like application of a reserved identifier.


No. I can't find *any* macro defined in your code, for that matter.
What's disallowed is to write something like this:

#include <string.h>
#define strobe0 42 /* UB, str[a-z]* used as macro name */
static int strobe; /* UB, str[a-z]* used as file scope identifier */

whereas e.g. the following TU is valid:

/* Look Ma, no string.h included. */
#define strobe0 42
static int strobe;

as well as this one:

#include <string.h>
int foo( void )
{
int strstr = 666; /* Look Ma, block scope identifier. */
return strstr;
}
I disagree with your assessment. The fact that a block scoped pointer
object holds the name of something (function or object) with external
linkage does not violate the standard requirement above. ...


It's the reserved use as a function macro which is the problem.


No. It's used as a simple block scope identifier, which is perfectly
fine (modulo it may shadow a 'strobe' identifier defined in some
future version of string.h, but that's the programmer's problem then,
and doesn't result in undefined behaviour a priori).

Regards
--
Irrwahn Grausewitz (ir*******@free net.de)
welcome to clc: http://www.ungerhu.com/jxh/clc.welcome.txt
clc faq-list : http://www.faqs.org/faqs/C-faq/faq/
clc OT guide : http://benpfaff.org/writings/clc/off-topic.html
Nov 14 '05 #9
"Irrwahn Grausewitz" <ir*******@free net.de> wrote in message
news:eq******** *************** *********@4ax.c om...
"Peter Nilsson" <ai***@acay.com .au> wrote:
"Jack Klein" <ja*******@spam cop.net> wrote in message
news:cm******* *************** **********@4ax. com...

On Sat, 26 Jun 2004 12:38:41 +1000, "Peter Nilsson"
<ai***@acay.com .au> wrote in comp.lang.c:

> "Vijay Kumar R Zanvar" <vi*****@global edgesoft.com> wrote in message
> news:2k******** *****@uni-berlin.de...
> >
> > "CBFalconer " <cb********@yah oo.com> wrote in message
> > news:40******** *******@yahoo.c om...
> > >
> > > In addition, names begining with "str" are reserved for the
> > > implementation. You should change those.
> >
> > IIRC, the restriction is not for the local variables. Please
> > correct me, if I understood it wrongly.
>
> See 7.1.3, 7.1.4 & 7.26
>
> Identifiers beginning with 'str' followed by at least one lower
> case letter are reserved for use as identifiers with external
> linkage. [In C90, such linkage is possibly case insensitive.]
> If <string.h> or <stdlib.h> is included, then they are reserved ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^
> as macro names and file scope identifiers too.

^^^^^^^^^^^^^^
>
> But it's still possible to declare a local (auto) variable and have
> problems...
>
> #include <string.h>
>
> void bar(int);
>
> void foo(void)
> {
> void (*strobe)(int) = bar; /* ok */
> strobe(42); /* UB */


This is a function macro like application of a reserved identifier.


No.


Huh? You don't think its a reserved identifier, or you don't think its a 'function macro
like' application?
I can't find *any* macro defined in your code, for that matter.


It's right there in the line...

#include <string.h>

Translation phases 1 through 4 occur long before any block scopes are identified by the
implementation.

My argument is quite simple: The identifier strobe is reserved as an external identifier,
therefore it is reserved as a macro whenever <string.h> or <stdlib.h> is included,
therefore a token sequence like...

strobe(42)

....is potentially a macro invocation, therefore it is potentially UB since no programmer
cannot possibly know the number of arguments the identifier will be defined with (until it
makes the standard as a prototyped function).

What am I missing?

--
Peter
Nov 14 '05 #10

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

Similar topics

4
36170
by: Dawn Minnis | last post by:
Hi When I compile my files I get the following: driver.c: In function `main': driver.c:49: warning: assignment makes integer from pointer without a cast driver.c:50: warning: assignment makes integer from pointer without a cast driver.c:51: warning: assignment makes integer from pointer without a
2
14309
by: francescomoi | last post by:
Hi. I'm trying to compile this piece of source: ------------------------------------------- int id; while(row1 = mysql_fetch_row(rs1)) { id = atoi((int)row1); -----------------------------------
26
3037
by: Bill Reid | last post by:
Bear with me, as I am not a "professional" programmer, but I was working on part of program that reads parts of four text files into a buffer which I re-allocate the size as I read each file. I read some of the items from the bottom up of the buffer, and some from the top down, moving the bottom items back to the new re-allocated bottom on...
3
17145
by: mrmattborja | last post by:
Hello, Here is a program I'm playing around with for fun in the process of learning C. The objective is to create a function filesize() and call it from within the main() section to retrieve the size in bytes of a file that I give it. #include <stdio.h> long filesize(f) { FILE *fp;
6
3543
by: Kinbote | last post by:
Hi, I'm trying to make a function that opens a file, reads it in line by line, puts each line into an malloc'd array, and returns the array. I suspect I'm going about it in an atypical fashion, as I'm avoiding the use of fscanf and fgets to read in lines. I don't want to have to specify a temporary char* buffer to read in each line, and then...
10
9485
drhowarddrfine
by: drhowarddrfine | last post by:
warning: assignment makes pointer from integer without a cast I get that when I compile a C file where the function is defined as this: char **getvars() and the calling function has this declared: char **s; and I write: s=getvars();
1
3762
by: woods1313drew | last post by:
The following code in c+ gives me the warning assignment makes integer from pointer without a cast. destination is set as char destination to limit the input string to 10 characters. name is an array of ten places char name iv looked in several books but cant find an references to integer pointer errors. Could someone tell me what i am doing...
0
7843
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...
0
8205
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. ...
1
7967
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...
0
8220
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...
0
6619
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5392
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3840
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...
0
3872
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2347
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.