Converting from C, need help

Everything else that doesn't fall into one of the other PB categories.
Seymour Clufley
Addict
Addict
Posts: 1267
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Converting from C, need help

Post by Seymour Clufley »

Can anyone tell me what "static inline void" would translate to in PB?

And would this:

Code: Select all

double s[16]
translate to:

Code: Select all

dim s.d(16)
?

The code is mostly wrapped inside a "namespace". Should I just ignore that?
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Converting from C, need help

Post by Trond »

Seymour Clufley wrote:Can anyone tell me what "static inline void" would translate to in PB?
That's the return type of a function, right? Then it would be nothing in PB:
And would this:

Code: Select all

double s[16]
translate to:

Code: Select all

dim s.d(16)
?
No. The C array is static with 16 elements, while the PB array is dynamic with 17 elements. Having one element too much usually won't hurt, though.
The code is mostly wrapped inside a "namespace". Should I just ignore that?
Yes.
Seymour Clufley
Addict
Addict
Posts: 1267
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Post by Seymour Clufley »

Thanks, Trond! That's very helpful.

Could you also explain some other parts...

Code: Select all

m4::id(s)
"m4" is a namespace, "id" is a function and "s" is a double array. So, in PB speak, is that code simply calling a procedure?

Code: Select all

assert((dx*dx + dy*dy)<1e-10);
The code has a line "include assert.h" and this is the only line of code that makes use of it. If I understand Wikipedia correctly, assert.h is just a debugging macro. So again, can I just ignore this?

Code: Select all

for(size_t j=0; j<4; ++j)
    {
        for(size_t i=0; i<4; ++i)
    {
        printf(m[i+4*j]);
    }
}
It's the first line I'm not sure of, as it seems to be using two variables (size_t and j) instead of just one.

Thanks again for your help, Trond.
User avatar
Hroudtwolf
Addict
Addict
Posts: 803
Joined: Sat Feb 12, 2005 3:35 am
Location: Germany(Hessen)
Contact:

Post by Hroudtwolf »

I suggest, this is the true PB equivalent to an static array in C....

Code: Select all

Structure tDoubleArray
   nValue.d [ 16 ]
EndStructure

Define.tDoubleArray MyArray

MyArray\nValue [ 0 ] = 1
Regards

Wolf
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Depending on what to do, for some cases, in PB i would do:

Code: Select all

DataSection
!s:
!rq 16
EndDataSection
And then refer to s label as it was the variable.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

size_t is just the typename and means j is of the type size_t (which is probably the same as unsigned long int).
Post Reply