C opaque struct
C opaque struct
I translated typedef struct foo_ctx foo_ctx; to type foo_ctx end type but fbc refused to compile. Please help.
Re: C opaque struct
the FB equivalent of typedef struct foo_ctx foo_ctx is type foo_ctx as foo_ctx, you remind me of the other member that was banned more than once, asking others to translate c headers for him while not taking the effort himself
Re: C opaque struct
No my friends. Not me
Well, I will only admit I'm lazy if you could show me exactly where the knowledge you given me is (which wiki page, which sections,...). Your wikis are lengthy, full of words and words, even though I tried to read it before asking but I still easily missed the needed information. So better ask, I have wasted hours reading your wikis without being able to extract the needed information. Only after being given the answer, I read that wiki page again and found it's located in a very difficult to see section and most of the time people will skip it thinking it's irrelevent. Your language is full of synatic sugar. Searching on the forum or via Google most of the time give irrelevant results. Most of the time, I don't know where to search or which search phrase to search. Well, the above: type sth as sth. Which search phrase will you use? I'm not even know how it's called. I searched with freebasic empty type, freebasic opaque type,... all give me nothing. It wasted of me more than two days to come up with a working translation. So, please, don't say I'm lazy or I'm lack of effort. I'm not lazy nor not spend the effort, only I'm get lost. My advice for other newbie is, it's better to ask, don't waste time reading their wiki, it's pointless!lal0qnsc wrote: ↑Apr 06, 2022 17:22 My translation works
fbfrog spng.h -rename_ width -rename_ alpha -rename_ type -rename_ name -rename_ year -rename_ month -rename_ day -rename_ hour -rename_ minute -rename_ second -rename_ data -rename_ len -rename_ error -rename_ option -rename_ out -rename_ errCode: Select all
#pragma once #include once "crt/stdlib.bi" #include once "crt/stdint.bi" #include once "crt/stdio.bi" extern "C" const SPNG_VERSION_MAJOR = 0 const SPNG_VERSION_MINOR = 7 const SPNG_VERSION_PATCH = 2 type spng_errno as long enum SPNG_IO_ERROR = -2 SPNG_IO_EOF = -1 SPNG_OK = 0 SPNG_EINVAL SPNG_EMEM SPNG_EOVERFLOW SPNG_ESIGNATURE SPNG_EWIDTH SPNG_EHEIGHT SPNG_EUSER_WIDTH SPNG_EUSER_HEIGHT SPNG_EBIT_DEPTH SPNG_ECOLOR_TYPE SPNG_ECOMPRESSION_METHOD SPNG_EFILTER_METHOD SPNG_EINTERLACE_METHOD SPNG_EIHDR_SIZE SPNG_ENOIHDR SPNG_ECHUNK_POS SPNG_ECHUNK_SIZE SPNG_ECHUNK_CRC SPNG_ECHUNK_TYPE SPNG_ECHUNK_UNKNOWN_CRITICAL SPNG_EDUP_PLTE SPNG_EDUP_CHRM SPNG_EDUP_GAMA SPNG_EDUP_ICCP SPNG_EDUP_SBIT SPNG_EDUP_SRGB SPNG_EDUP_BKGD SPNG_EDUP_HIST SPNG_EDUP_TRNS SPNG_EDUP_PHYS SPNG_EDUP_TIME SPNG_EDUP_OFFS SPNG_EDUP_EXIF SPNG_ECHRM SPNG_EPLTE_IDX SPNG_ETRNS_COLOR_TYPE SPNG_ETRNS_NO_PLTE SPNG_EGAMA SPNG_EICCP_NAME SPNG_EICCP_COMPRESSION_METHOD SPNG_ESBIT SPNG_ESRGB SPNG_ETEXT SPNG_ETEXT_KEYWORD SPNG_EZTXT SPNG_EZTXT_COMPRESSION_METHOD SPNG_EITXT SPNG_EITXT_COMPRESSION_FLAG SPNG_EITXT_COMPRESSION_METHOD SPNG_EITXT_LANG_TAG SPNG_EITXT_TRANSLATED_KEY SPNG_EBKGD_NO_PLTE SPNG_EBKGD_PLTE_IDX SPNG_EHIST_NO_PLTE SPNG_EPHYS SPNG_ESPLT_NAME SPNG_ESPLT_DUP_NAME SPNG_ESPLT_DEPTH SPNG_ETIME SPNG_EOFFS SPNG_EEXIF SPNG_EIDAT_TOO_SHORT SPNG_EIDAT_STREAM SPNG_EZLIB SPNG_EFILTER SPNG_EBUFSIZ SPNG_EIO SPNG_EOF SPNG_EBUF_SET SPNG_EBADSTATE SPNG_EFMT SPNG_EFLAGS SPNG_ECHUNKAVAIL SPNG_ENCODE_ONLY SPNG_EOI SPNG_ENOPLTE SPNG_ECHUNK_LIMITS SPNG_EZLIB_INIT SPNG_ECHUNK_STDLEN SPNG_EINTERNAL SPNG_ECTXTYPE SPNG_ENOSRC SPNG_ENODST SPNG_EOPSTATE SPNG_ENOTFINAL end enum type spng_text_type as long enum SPNG_TEXT = 1 SPNG_ZTXT = 2 SPNG_ITXT = 3 end enum type spng_color_type as long enum SPNG_COLOR_TYPE_GRAYSCALE = 0 SPNG_COLOR_TYPE_TRUECOLOR = 2 SPNG_COLOR_TYPE_INDEXED = 3 SPNG_COLOR_TYPE_GRAYSCALE_ALPHA = 4 SPNG_COLOR_TYPE_TRUECOLOR_ALPHA = 6 end enum type spng_filter as long enum SPNG_FILTER_NONE = 0 SPNG_FILTER_SUB = 1 SPNG_FILTER_UP = 2 SPNG_FILTER_AVERAGE = 3 SPNG_FILTER_PAETH = 4 end enum type spng_filter_choice as long enum SPNG_DISABLE_FILTERING = 0 SPNG_FILTER_CHOICE_NONE = 8 SPNG_FILTER_CHOICE_SUB = 16 SPNG_FILTER_CHOICE_UP = 32 SPNG_FILTER_CHOICE_AVG = 64 SPNG_FILTER_CHOICE_PAETH = 128 SPNG_FILTER_CHOICE_ALL = (((8 or 16) or 32) or 64) or 128 end enum type spng_interlace_method as long enum SPNG_INTERLACE_NONE = 0 SPNG_INTERLACE_ADAM7 = 1 end enum type spng_format as long enum SPNG_FMT_RGBA8 = 1 SPNG_FMT_RGBA16 = 2 SPNG_FMT_RGB8 = 4 SPNG_FMT_GA8 = 16 SPNG_FMT_GA16 = 32 SPNG_FMT_G8 = 64 SPNG_FMT_PNG = 256 SPNG_FMT_RAW = 512 end enum type spng_ctx_flags as long enum SPNG_CTX_IGNORE_ADLER32 = 1 SPNG_CTX_ENCODER = 2 end enum type spng_decode_flags as long enum SPNG_DECODE_USE_TRNS = 1 SPNG_DECODE_USE_GAMA = 2 SPNG_DECODE_USE_SBIT = 8 SPNG_DECODE_TRNS = 1 SPNG_DECODE_GAMMA = 2 SPNG_DECODE_PROGRESSIVE = 256 end enum type spng_crc_action as long enum SPNG_CRC_ERROR = 0 SPNG_CRC_DISCARD = 1 SPNG_CRC_USE = 2 end enum type spng_encode_flags as long enum SPNG_ENCODE_PROGRESSIVE = 1 SPNG_ENCODE_FINALIZE = 2 end enum type spng_ihdr width_ as ulong height as ulong bit_depth as ubyte color_type as ubyte compression_method as ubyte filter_method as ubyte interlace_method as ubyte end type type spng_plte_entry red as ubyte green as ubyte blue as ubyte alpha_ as ubyte end type type spng_plte n_entries as ulong entries(0 to 255) as spng_plte_entry end type type spng_trns gray as ushort red as ushort green as ushort blue as ushort n_type3_entries as ulong type3_alpha(0 to 255) as ubyte end type type spng_chrm_int white_point_x as ulong white_point_y as ulong red_x as ulong red_y as ulong green_x as ulong green_y as ulong blue_x as ulong blue_y as ulong end type type spng_chrm white_point_x as double white_point_y as double red_x as double red_y as double green_x as double green_y as double blue_x as double blue_y as double end type type spng_iccp profile_name as zstring * 80 profile_len as uinteger profile as zstring ptr end type type spng_sbit grayscale_bits as ubyte red_bits as ubyte green_bits as ubyte blue_bits as ubyte alpha_bits as ubyte end type type spng_text keyword as zstring * 80 type_ as long length as uinteger text as zstring ptr compression_flag as ubyte compression_method as ubyte language_tag as zstring ptr translated_keyword as zstring ptr end type type spng_bkgd gray as ushort red as ushort green as ushort blue as ushort plte_index as ushort end type type spng_hist frequency(0 to 255) as ushort end type type spng_phys ppu_x as ulong ppu_y as ulong unit_specifier as ubyte end type type spng_splt_entry red as ushort green as ushort blue as ushort alpha_ as ushort frequency as ushort end type type spng_splt name_ as zstring * 80 sample_depth as ubyte n_entries as ulong entries as spng_splt_entry ptr end type type spng_time year_ as ushort month_ as ubyte day_ as ubyte hour_ as ubyte minute_ as ubyte second_ as ubyte end type type spng_offs x as long y as long unit_specifier as ubyte end type type spng_exif length as uinteger data_ as zstring ptr end type type spng_chunk offset as uinteger length as ulong type_(0 to 3) as ubyte crc as ulong end type type spng_location as long enum SPNG_AFTER_IHDR = 1 SPNG_AFTER_PLTE = 2 SPNG_AFTER_IDAT = 8 end enum type spng_unknown_chunk type_(0 to 3) as ubyte length as uinteger data_ as any ptr location as spng_location end type type spng_option as long enum SPNG_KEEP_UNKNOWN_CHUNKS = 1 SPNG_IMG_COMPRESSION_LEVEL SPNG_IMG_WINDOW_BITS SPNG_IMG_MEM_LEVEL SPNG_IMG_COMPRESSION_STRATEGY SPNG_TEXT_COMPRESSION_LEVEL SPNG_TEXT_WINDOW_BITS SPNG_TEXT_MEM_LEVEL SPNG_TEXT_COMPRESSION_STRATEGY SPNG_FILTER_CHOICE SPNG_CHUNK_COUNT_LIMIT SPNG_ENCODE_TO_BUFFER end enum type spng_alloc malloc_fn as function(byval size as uinteger) as any ptr realloc_fn as function(byval ptr as any ptr, byval size as uinteger) as any ptr calloc_fn as function(byval count as uinteger, byval size as uinteger) as any ptr free_fn as sub(byval ptr as any ptr) end type type spng_row_info scanline_idx as ulong row_num as ulong pass as long filter as ubyte end type type spng_ctx as spng_ctx type spng_read_fn as function (byval ctx as spng_ctx ptr, byval user as any ptr, byval dest as any ptr, byval length as uinteger) as long type spng_write_fn as function (byval ctx as spng_ctx ptr, byval user as any ptr, byval src as any ptr, byval length as uinteger) as long type spng_rw_fn as function (byval ctx as spng_ctx ptr, byval user as any ptr, byval dst_src as any ptr, byval length as uinteger) as long declare function spng_ctx_new(byval flags as long) as spng_ctx ptr declare function spng_ctx_new2(byval alloc as spng_alloc ptr, byval flags as long) as spng_ctx ptr declare sub spng_ctx_free(byval ctx as spng_ctx ptr) declare function spng_set_png_buffer(byval ctx as spng_ctx ptr, byval buf as const any ptr, byval size as uinteger) as long declare function spng_set_png_stream(byval ctx as spng_ctx ptr, byval rw_func as function(byval ctx as spng_ctx ptr, byval user as any ptr, byval dst_src as any ptr, byval length as uinteger) as long, byval user as any ptr) as long declare function spng_set_png_file(byval ctx as spng_ctx ptr, byval file as FILE ptr) as long declare function spng_get_png_buffer(byval ctx as spng_ctx ptr, byval len_ as uinteger ptr, byval error_ as long ptr) as any ptr declare function spng_set_image_limits(byval ctx as spng_ctx ptr, byval width_ as ulong, byval height as ulong) as long declare function spng_get_image_limits(byval ctx as spng_ctx ptr, byval width_ as ulong ptr, byval height as ulong ptr) as long declare function spng_set_chunk_limits(byval ctx as spng_ctx ptr, byval chunk_size as uinteger, byval cache_size as uinteger) as long declare function spng_get_chunk_limits(byval ctx as spng_ctx ptr, byval chunk_size as uinteger ptr, byval cache_size as uinteger ptr) as long declare function spng_set_crc_action(byval ctx as spng_ctx ptr, byval critical as long, byval ancillary as long) as long declare function spng_set_option(byval ctx as spng_ctx ptr, byval option_ as spng_option, byval value as long) as long declare function spng_get_option(byval ctx as spng_ctx ptr, byval option_ as spng_option, byval value as long ptr) as long declare function spng_decoded_image_size(byval ctx as spng_ctx ptr, byval fmt as long, byval len_ as uinteger ptr) as long declare function spng_decode_image(byval ctx as spng_ctx ptr, byval out_ as any ptr, byval len_ as uinteger, byval fmt as long, byval flags as long) as long declare function spng_decode_scanline(byval ctx as spng_ctx ptr, byval out_ as any ptr, byval len_ as uinteger) as long declare function spng_decode_row(byval ctx as spng_ctx ptr, byval out_ as any ptr, byval len_ as uinteger) as long declare function spng_decode_chunks(byval ctx as spng_ctx ptr) as long declare function spng_get_row_info(byval ctx as spng_ctx ptr, byval row_info as spng_row_info ptr) as long declare function spng_encode_image(byval ctx as spng_ctx ptr, byval img as const any ptr, byval len_ as uinteger, byval fmt as long, byval flags as long) as long declare function spng_encode_scanline(byval ctx as spng_ctx ptr, byval scanline as const any ptr, byval len_ as uinteger) as long declare function spng_encode_row(byval ctx as spng_ctx ptr, byval row as const any ptr, byval len_ as uinteger) as long declare function spng_encode_chunks(byval ctx as spng_ctx ptr) as long declare function spng_get_ihdr(byval ctx as spng_ctx ptr, byval ihdr as spng_ihdr ptr) as long declare function spng_get_plte(byval ctx as spng_ctx ptr, byval plte as spng_plte ptr) as long declare function spng_get_trns(byval ctx as spng_ctx ptr, byval trns as spng_trns ptr) as long declare function spng_get_chrm(byval ctx as spng_ctx ptr, byval chrm as spng_chrm ptr) as long declare function spng_get_chrm_int(byval ctx as spng_ctx ptr, byval chrm_int as spng_chrm_int ptr) as long declare function spng_get_gama(byval ctx as spng_ctx ptr, byval gamma as double ptr) as long declare function spng_get_gama_int(byval ctx as spng_ctx ptr, byval gama_int as ulong ptr) as long declare function spng_get_iccp(byval ctx as spng_ctx ptr, byval iccp as spng_iccp ptr) as long declare function spng_get_sbit(byval ctx as spng_ctx ptr, byval sbit as spng_sbit ptr) as long declare function spng_get_srgb(byval ctx as spng_ctx ptr, byval rendering_intent as ubyte ptr) as long declare function spng_get_text(byval ctx as spng_ctx ptr, byval text as spng_text ptr, byval n_text as ulong ptr) as long declare function spng_get_bkgd(byval ctx as spng_ctx ptr, byval bkgd as spng_bkgd ptr) as long declare function spng_get_hist(byval ctx as spng_ctx ptr, byval hist as spng_hist ptr) as long declare function spng_get_phys(byval ctx as spng_ctx ptr, byval phys as spng_phys ptr) as long declare function spng_get_splt(byval ctx as spng_ctx ptr, byval splt as spng_splt ptr, byval n_splt as ulong ptr) as long declare function spng_get_time(byval ctx as spng_ctx ptr, byval time as spng_time ptr) as long declare function spng_get_unknown_chunks(byval ctx as spng_ctx ptr, byval chunks as spng_unknown_chunk ptr, byval n_chunks as ulong ptr) as long declare function spng_get_offs(byval ctx as spng_ctx ptr, byval offs as spng_offs ptr) as long declare function spng_get_exif(byval ctx as spng_ctx ptr, byval exif as spng_exif ptr) as long declare function spng_set_ihdr(byval ctx as spng_ctx ptr, byval ihdr as spng_ihdr ptr) as long declare function spng_set_plte(byval ctx as spng_ctx ptr, byval plte as spng_plte ptr) as long declare function spng_set_trns(byval ctx as spng_ctx ptr, byval trns as spng_trns ptr) as long declare function spng_set_chrm(byval ctx as spng_ctx ptr, byval chrm as spng_chrm ptr) as long declare function spng_set_chrm_int(byval ctx as spng_ctx ptr, byval chrm_int as spng_chrm_int ptr) as long declare function spng_set_gama(byval ctx as spng_ctx ptr, byval gamma as double) as long declare function spng_set_gama_int(byval ctx as spng_ctx ptr, byval gamma as ulong) as long declare function spng_set_iccp(byval ctx as spng_ctx ptr, byval iccp as spng_iccp ptr) as long declare function spng_set_sbit(byval ctx as spng_ctx ptr, byval sbit as spng_sbit ptr) as long declare function spng_set_srgb(byval ctx as spng_ctx ptr, byval rendering_intent as ubyte) as long declare function spng_set_text(byval ctx as spng_ctx ptr, byval text as spng_text ptr, byval n_text as ulong) as long declare function spng_set_bkgd(byval ctx as spng_ctx ptr, byval bkgd as spng_bkgd ptr) as long declare function spng_set_hist(byval ctx as spng_ctx ptr, byval hist as spng_hist ptr) as long declare function spng_set_phys(byval ctx as spng_ctx ptr, byval phys as spng_phys ptr) as long declare function spng_set_splt(byval ctx as spng_ctx ptr, byval splt as spng_splt ptr, byval n_splt as ulong) as long declare function spng_set_time(byval ctx as spng_ctx ptr, byval time as spng_time ptr) as long declare function spng_set_unknown_chunks(byval ctx as spng_ctx ptr, byval chunks as spng_unknown_chunk ptr, byval n_chunks as ulong) as long declare function spng_set_offs(byval ctx as spng_ctx ptr, byval offs as spng_offs ptr) as long declare function spng_set_exif(byval ctx as spng_ctx ptr, byval exif as spng_exif ptr) as long declare function spng_strerror(byval err_ as long) as const zstring ptr declare function spng_version_string() as const zstring ptr end extern
then edit manually
p/s: even if will get banned, I will still tell you these words what I'm truly want you to know Let me tell you again, searching C empty struct or C opaque struct give you millions of results and the first result is relevant, it really tell you what you want to know. Searching freebasic empty type, freebasic opaque type,... only gives you irrelevant nonsense
Re: C opaque struct
you show a good sense of humor, which is good
maybe someone more knowledgeable than me will answer your queries
maybe someone more knowledgeable than me will answer your queries
Re: C opaque struct
By using the FB-manual-*.chm and the search function, you can quickly find the relevant pages and see the search terms highlighted there.
Re: C opaque struct
I don't know why I wrote that much. I'm usually not. Perhaps because I hate someone telling me lazy, because I'm really not. You should do the search yourself to see I'm not lie. Searching for anything freebasic is pretty much pointless as it will go to nowhere. Most of the time the result is documentation.help (which is an outdated version of freebasic.net wiki), or some irrelevent forum threads. It's pretty much... hopeless, you can't find the answer that way! Reading through wiki to find it manually by your very own eyes? Nah. Wiki is too lengthy, you will easily miss the very information you wanted to know!
Long story short: I don't know what I'm searching for called. How could I search for it? Google doesn't help. Google only brings nonsense. The only way is brute force, searching any wiki pages available. Could be limit to the pages you think the content you searching for should be there. But, I was fooled by this assumption once. The information I wanted to know, instead on another wiki page I'm not yet read and IMO has nothing to do which what I wanted to search for. The moderator @fxm has done his best, I'm acknowledge this and I know it's ungraceful to say don't read the wiki but ask, but... I'm really got headache when reading his wiki
Re: C opaque struct
Where to download it? I really don't know about the existent of it nor I know I could search on chm. I did see many chm files, open them to read something, but I have never done anything further with them
Re: C opaque struct
Well, I'm finally find it by digging files of the fbc project on sourceforges
https://sourceforge.net/projects/fbc/fi ... mentation/
Shouldn't it be part of the freebasic distribution? Free Pascal shipped the chm with their installation (I admit I have never read, searching on Google is far more quicker with Free Pascal).
https://sourceforge.net/projects/fbc/fi ... mentation/
Shouldn't it be part of the freebasic distribution? Free Pascal shipped the chm with their installation (I admit I have never read, searching on Google is far more quicker with Free Pascal).
Re: C opaque struct
You can find all the relevant files in FreeBASIC / News / Version 1.09.0 Released.
Re: C opaque struct
The information is here: https://www.freebasic.net/wiki/KeyPgTypeAlias
No obvious example. You have to read the text to infer it. Type sth As sth is used for foward declaration and can only be used with pointers, pretty much like it C counterpart. I don't know that it's called Type Alias. I read the wiki for Type...End Type many times but didn't find the answer.
No obvious example. You have to read the text to infer it. Type sth As sth is used for foward declaration and can only be used with pointers, pretty much like it C counterpart. I don't know that it's called Type Alias. I read the wiki for Type...End Type many times but didn't find the answer.
Re: C opaque struct
These 2 pages might interest you:
- https://www.freebasic.net/wiki/TblComparisonC
- https://www.freebasic.net/wiki/TblComparisonCTypes
- https://www.freebasic.net/wiki/TblComparisonC
- https://www.freebasic.net/wiki/TblComparisonCTypes
Re: C opaque struct
You wont find guides to translate from C to FB. You'll have to learn the syntax of both languages, try and test your translation, and then write and publish your own guide.
declares a pointer to a structure with private context (unknown members). Doesn't fbfrog provide a translation? h_2_bi does:
Code: Select all
' typedef struct foo_ctx foo_ctx;
TYPE AS foo_ctx_ foo_ctx
' or
TYPE AS ANY PTR foo_ctx
Re: C opaque struct
No. fbfrog just ignore them altogether. It's me who try to translate it manually. Compared to h_2_bi, it seems h_2_bi is much more powerful. But fbfrog due to being part of the freebasic project (hosted as a freebasic project's repository at github.com/freebasic/fbfrog), is much more popular.TJF wrote: ↑Apr 06, 2022 19:09 You wont find guides to translate from C to FB. You'll have to learn the syntax of both languages, try and test your translation, and then write and publish your own guide.
declares a pointer to a structure with private context (unknown members). Doesn't fbfrog provide a translation? h_2_bi does:Code: Select all
' typedef struct foo_ctx foo_ctx; TYPE AS foo_ctx_ foo_ctx ' or TYPE AS ANY PTR foo_ctx
Re: C opaque struct
Have Type Alias example but the example is about normal type (integer). In no way someone could know the very same syntax also used for UDT. You should add at least C function typedef (viewtopic.php?t=31606) and this C opaque struct (Type sth As sth). This will help very much.fxm wrote: ↑Apr 06, 2022 19:01 These 2 pages might interest you:
- https://www.freebasic.net/wiki/TblComparisonC
- https://www.freebasic.net/wiki/TblComparisonCTypes
Re: C opaque struct
That doesn't mean the Wiki is pointless/useless, just highlights your lack of knowledge.
Oh no, you just happen to have a similar nickname (just an assortment of letters), ask the same questions, and have the same dislike for reading text.