unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Are char* and signed char* compatible (SCM_BYTEVECTOR_CONTENTS)?
@ 2021-02-26  9:33 Vivien Kraus via General Guile related discussions
  2021-02-26 11:15 ` Mike Gran
  0 siblings, 1 reply; 2+ messages in thread
From: Vivien Kraus via General Guile related discussions @ 2021-02-26  9:33 UTC (permalink / raw)
  To: guile-user

Hello,

I’m trying to use a bytevector from C.

1. According to an example in the manual, SCM_BYTEVECTOR_CONTENTS can
be assigned to a char*.

2. Also from the manual, it is a signed char*.

3. I've found this question online saying they are not compatible (
https://stackoverflow.com/questions/12769500/why-is-char-not-compatible-with-signed-char-or-unsigned-char
).

As I understand it, at least one of the above 3 affirmations is
incorrect. Could someone clarify this to me?




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

* Re: Are char* and signed char* compatible (SCM_BYTEVECTOR_CONTENTS)?
  2021-02-26  9:33 Are char* and signed char* compatible (SCM_BYTEVECTOR_CONTENTS)? Vivien Kraus via General Guile related discussions
@ 2021-02-26 11:15 ` Mike Gran
  0 siblings, 0 replies; 2+ messages in thread
From: Mike Gran @ 2021-02-26 11:15 UTC (permalink / raw)
  To: Vivien Kraus, guile-user

On Fri, 2021-02-26 at 10:33 +0100, Vivien Kraus via General Guile
related discussions wrote:
> Hello,
> 
> I’m trying to use a bytevector from C.
> 
> 1. According to an example in the manual, SCM_BYTEVECTOR_CONTENTS can
> be assigned to a char*.
> 
> 2. Also from the manual, it is a signed char*.
> 
> 3. I've found this question online saying they are not compatible (
> https://stackoverflow.com/questions/12769500/why-is-char-not-compatible-with-signed-char-or-unsigned-char
> ).
> 
> As I understand it, at least one of the above 3 affirmations is
> incorrect. Could someone clarify this to me?

Depending on your compiler and OS, char is either signed char (-128 to
127) or unsigned char (0 to 255).  It is probably signed char.

You are free to cast the contents of a bytevector as signed char *,
unsigned char *, or char * (which is probably signed char).  It depends
on what you want.  When you use a  bytevector from within Guile, it
will appear as unsigned 8=bit integers. But from within guile you could
use bytevector-s8-ref if you wanted to pull a byte out as a signed 8-
bit integer.

-Mike





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

end of thread, other threads:[~2021-02-26 11:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-26  9:33 Are char* and signed char* compatible (SCM_BYTEVECTOR_CONTENTS)? Vivien Kraus via General Guile related discussions
2021-02-26 11:15 ` Mike Gran

unofficial mirror of guile-user@gnu.org 

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://yhetil.org/guile-user/0 guile-user/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 guile-user guile-user/ https://yhetil.org/guile-user \
		guile-user@gnu.org
	public-inbox-index guile-user

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.yhetil.org/yhetil.lisp.guile.user
	nntp://news.gmane.io/gmane.lisp.guile.user


AGPL code for this site: git clone http://ou63pmih66umazou.onion/public-inbox.git