C to Freebasic code snippets help

New to FreeBASIC? Post your questions here.
Post Reply
stan1958
Posts: 5
Joined: Oct 24, 2020 21:17

C to Freebasic code snippets help

Post by stan1958 »

Seek help from seniors for the below code conversion C to FB

Code: Select all

C code:

static inline void memfill32(uint32_t* dest, uint32_t value, int length)
{
    for(int i = 0;i < length;i++)
        dest[i] = value;
}

FB converted code:

private sub memfill32(byval dest as ulong ptr, byval value as ulong, byval length as long)
    For i As integer  = 1 to length  ' hope this line is correct related to the below line
	    dest[i] = value;               'No idea how to convert could not find any clue even in rossetta code
	  Next
end sub

Code: Select all

C code

font_data_t* font_data_reference(font_data_t* idata)
{
    if(idata == NULL)
        return NULL;

    ++idata->ref;
    return idata;
}

possible FB converted :

function font_data_reference(byval idata as font_data_t ptr) as font_data_t ptr
	if idata = NULL then
		return NULL
	end if
		++idata->ref;  ' No clue how to convert the pre- increment  
	return idata
end function
In general i have no clue how to handle the pre-increment for next loop procedure.

Br

Stan
paul doe
Moderator
Posts: 1793
Joined: Jul 25, 2017 17:22
Location: Argentina
Contact:

Re: C to Freebasic code snippets help

Post by paul doe »

stan1958 wrote: Sep 09, 2024 0:58 Seek help from seniors for the below code conversion C to FB

Code: Select all

C code:

static inline void memfill32(uint32_t* dest, uint32_t value, int length)
{
  for(int i = 0;i < length;i++)
    dest[i] = value;
}

FB converted code:

private sub memfill32(byval dest as ulong ptr, byval value as ulong, byval length as long)
  For i As integer  = 0 to length - 1  ' Nope; this is how you port that C idiom to FreeBasic
    dest[i] = value               'Because you should look at the manual and not Rosetta Code ;)
  Next
end sub
As for this:

Code: Select all

C code

font_data_t* font_data_reference(font_data_t* idata)
{
  if(idata == NULL)
    return NULL;

  ++idata->ref;
  return idata;
}

possible FB converted :

function font_data_reference(byval idata as font_data_t ptr) as font_data_t ptr
  if idata = NULL then
    return NULL
  end if
  
  idata->ref += 1 ' In this case it doesn't matter if it's pre or post increment; just increment it
  
  return idata
end function
In general i have no clue how to handle the pre-increment for next loop procedure.

Br

Stan
stan1958
Posts: 5
Joined: Oct 24, 2020 21:17

Re: C to Freebasic code snippets help

Post by stan1958 »

Thank you Paul :)
Post Reply