Library SC: Portable, stand-alone C libraries and data structures

Headers, Bindings, Libraries for use with FreeBASIC, Please include example of use to help ensure they are tested and usable.
Post Reply
j8w344c6
Posts: 184
Joined: Oct 25, 2021 10:18

Library SC: Portable, stand-alone C libraries and data structures

Post by j8w344c6 »

I'm exploring it. You could get it here: https://github.com/tezc/sc

sc_crc32.bi

Code: Select all

#pragma once

#include once "crt/stdint.bi"

extern "C"

#define SC_CRC32_H
#define SC_CRC32_VERSION "2.0.0"
declare sub sc_crc32_init()
declare function sc_crc32(byval crc as ulong, byval buf as const ubyte ptr, byval len as ulong) as ulong

end extern
sc_ini.bi

Code: Select all

#pragma once

#include once "stdbool.bi"
#include once "crt/stddef.bi"
#include once "crt/stdio.bi"

extern "C"

#define SC_INI_H
#define SC_INI_VERSION "2.0.0"
const SC_INI_MAX_LINE_LEN = 1024
type sc_ini_on_item as function(byval arg as any ptr, byval line as long, byval section as const zstring ptr, byval key as const zstring ptr, byval value as const zstring ptr) as long
declare function sc_ini_parse_file(byval arg as any ptr, byval on_item as sc_ini_on_item, byval filename as const zstring ptr) as long
declare function sc_ini_parse_string(byval arg as any ptr, byval on_item as sc_ini_on_item, byval str as const zstring ptr) as long

end extern
Edit: examples and tests removed because they are failed to compile
Last edited by j8w344c6 on Dec 19, 2021 10:18, edited 2 times in total.
j8w344c6
Posts: 184
Joined: Oct 25, 2021 10:18

Re: Library SC: Portable, stand-alone C libraries and data structures

Post by j8w344c6 »

Anyone good enough in FreeBASIC please help me translating these into FreeBASIC code. I'm still very new to the language. My translations failed to compile. Thanks.

https://github.com/tezc/sc/blob/master/ ... _example.c
https://github.com/tezc/sc/blob/master/ ... c32_test.c
https://github.com/tezc/sc/blob/master/ ... _example.c
https://github.com/tezc/sc/blob/master/ini/ini_test.c
j8w344c6
Posts: 184
Joined: Oct 25, 2021 10:18

Re: Library SC: Portable, stand-alone C libraries and data structures

Post by j8w344c6 »

I have translated another similar C library. You could find it here:

viewtopic.php?f=14&t=29780
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Library SC: Portable, stand-alone C libraries and data structures

Post by fxm »

j8w344c6 wrote:Anyone good enough in FreeBASIC please help me translating these into FreeBASIC code. I'm still very new to the language. My translations failed to compile. Thanks.

https://github.com/tezc/sc/blob/master/ ... _example.c
https://github.com/tezc/sc/blob/master/ ... c32_test.c
https://github.com/tezc/sc/blob/master/ ... _example.c
https://github.com/tezc/sc/blob/master/ini/ini_test.c
It is by failing but persevering that we learn the most.
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Re: Library SC: Portable, stand-alone C libraries and data structures

Post by srvaldez »

hello j8w344c6
just an observation, in order to compile the afore mentioned example you need to either translate sc_crc32.c to fb or compile with C and include that object, I would make a lib even if it's just one object
I am not motivated at the moment to do the work for you
marcov
Posts: 3455
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: Library SC: Portable, stand-alone C libraries and data structures

Post by marcov »

(some hashes like MD5 and SHA1 use bit-rotation primitives/intrinsics to speed them up. Translating into a language that doesn't have them might be suboptimal)
j8w344c6
Posts: 184
Joined: Oct 25, 2021 10:18

Re: Library SC: Portable, stand-alone C libraries and data structures

Post by j8w344c6 »

fxm wrote:
j8w344c6 wrote:Anyone good enough in FreeBASIC please help me translating these into FreeBASIC code. I'm still very new to the language. My translations failed to compile. Thanks.

https://github.com/tezc/sc/blob/master/ ... _example.c
https://github.com/tezc/sc/blob/master/ ... c32_test.c
https://github.com/tezc/sc/blob/master/ ... _example.c
https://github.com/tezc/sc/blob/master/ini/ini_test.c
It is by failing but persevering that we learn the most.
Indeed I went for another C library which is more tempting to me than this one.
Last edited by j8w344c6 on Dec 20, 2021 0:14, edited 1 time in total.
j8w344c6
Posts: 184
Joined: Oct 25, 2021 10:18

Re: Library SC: Portable, stand-alone C libraries and data structures

Post by j8w344c6 »

srvaldez wrote:hello j8w344c6
just an observation, in order to compile the afore mentioned example you need to either translate sc_crc32.c to fb or compile with C and include that object, I would make a lib even if it's just one object
I am not motivated at the moment to do the work for you
Yes. I think I would use gcc -c to turn the sc_crc32.c to an object file then tell fbc to link with it. The build system of this library is cmake which can be easily installed on MSYS2 but since I don't have my MSYS2 shell now (have to uninstall it to make room for VS Studio Community) I can't compile the library. I will keep VS Studio Community for a while and I have another C library more tempting to me than this one to check out.

BTW, don't worry, I know how to compile using cmake.
j8w344c6
Posts: 184
Joined: Oct 25, 2021 10:18

Re: Library SC: Portable, stand-alone C libraries and data structures

Post by j8w344c6 »

marcov wrote:(some hashes like MD5 and SHA1 use bit-rotation primitives/intrinsics to speed them up. Translating into a language that doesn't have them might be suboptimal)
Yes. I don't know about what you said (bit-rotation primitives/intrinsics) but translating sc_crc32.c to FreeBASIC is impossible for me anyway.
marcov
Posts: 3455
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: Library SC: Portable, stand-alone C libraries and data structures

Post by marcov »

j8w344c6 wrote:
marcov wrote:(some hashes like MD5 and SHA1 use bit-rotation primitives/intrinsics to speed them up. Translating into a language that doesn't have them might be suboptimal)
Yes. I don't know about what you said (bit-rotation primitives/intrinsics) but translating sc_crc32.c to FreeBASIC is impossible for me anyway.
Bit rotation are assembler instructions that are like shifts, but put the bit that is shifted out at one end, into the other. So a shift right where the bit 0 goes to 7/15/31/63 (depending on byte/word/dword/qword instruction) and a shift left the other way around, the high bit into the low bit.

To access them from a higher level language there are intrinsics, which are pseudo functions defined in the compiler.If you use that function, the compiler knows to issue the instruction on architectures that support it, and emulates (with shifts and or) on other architectures.

Intrinsics for such tasks are usually better than assembler, since assembler is harder to inline, and leaves register allocation entirely free.
Post Reply