linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: using 'int char' with #define's variables.
  2002-09-01 22:35 using 'int char' with #define's variables Nick Jennings
@ 2002-09-01 22:28 ` Adam Kropelin
  2002-09-02  1:16 ` Stephen Satchell
  1 sibling, 0 replies; 3+ messages in thread
From: Adam Kropelin @ 2002-09-01 22:28 UTC (permalink / raw)
  To: linux-c-programming

----- Original Message -----
From: "Nick Jennings" <nkj@namodn.com>
To: <linux-c-programming@vger.kernel.org>
Sent: Sunday, September 01, 2002 6:35 PM
Subject: using 'int char' with #define's variables.


> Hi All,
>
>   A function that has a prototype of:
>
> char * strrchr( char * str, int ch );
>
>   It takes a character as an int in that second param.
>
>   I am having trouble using it with a #define's VAR.
>
> ---
> #define DIRMARK "/"

That's a string (i.e., a char*), not a char.
Double quotes give you a string, single quotes give you a char.

/* This is a pointer to a null-terminated string of characters */
#define DIRMARK "/"

/* This is a single char */
#define DIRMARK '/'

> gcc complains:
> warning: passing arg 2 of `strrchr' makes integer from pointer without a cast

...which is exactly what's happening. You're passing a char* where it expects an
int.

--Adam



^ permalink raw reply	[flat|nested] 3+ messages in thread

* using 'int char' with #define's variables.
@ 2002-09-01 22:35 Nick Jennings
  2002-09-01 22:28 ` Adam Kropelin
  2002-09-02  1:16 ` Stephen Satchell
  0 siblings, 2 replies; 3+ messages in thread
From: Nick Jennings @ 2002-09-01 22:35 UTC (permalink / raw)
  To: linux-c-programming

Hi All,

  A function that has a prototype of:

char * strrchr( char * str, int ch );

  It takes a character as an int in that second param.
 
  I am having trouble using it with a #define's VAR.

---
#define DIRMARK "/"

...

char * filename = strrchr(path, DIRMARK);
fprintf(stderr, "debug: filename = %s\n", filename);
---

gcc complains:
warning: passing arg 2 of `strrchr' makes integer from pointer without a cast

  It compiles, but doesn't seem to work right:

debug: filename = (null)


Any suggestions?

- Nick


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: using 'int char' with #define's variables.
  2002-09-01 22:35 using 'int char' with #define's variables Nick Jennings
  2002-09-01 22:28 ` Adam Kropelin
@ 2002-09-02  1:16 ` Stephen Satchell
  1 sibling, 0 replies; 3+ messages in thread
From: Stephen Satchell @ 2002-09-02  1:16 UTC (permalink / raw)
  To: Nick Jennings, linux-c-programming

At 03:35 PM 9/1/02 -0700, Nick Jennings wrote:
>char * strrchr( char * str, int ch );
>
>   It takes a character as an int in that second param.
>
>   I am having trouble using it with a #define's VAR.
>
>---
>#define DIRMARK "/"
>
>...
>
>char * filename = strrchr(path, DIRMARK);

Your #define is of type array of char, not a plain chiar. If you were to 
define it as

#define DIRMARK '/'

it would work better.

(note single-quote instead of double-quote)


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-09-02  1:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-09-01 22:35 using 'int char' with #define's variables Nick Jennings
2002-09-01 22:28 ` Adam Kropelin
2002-09-02  1:16 ` Stephen Satchell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).