Basic to C translation - Need Help

This is a discussion on Basic to C translation - Need Help within the C Programming forums, part of the General Programming Boards category; Hi, as the name of the thread indicates, i'm having a lot of troubles converting some Basic code to C. ...

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    1

    Basic to C translation - Need Help

    Hi, as the name of the thread indicates, i'm having a lot of troubles converting some Basic code to C. Can somebody help me doing this ?

    Here's some of the code, with this bit translated i think i can do the rest by myself.

    Code:
    '' internals
    
    declare sub regInitClass _
            ( _
                    byval this_ as REGCLASS ptr, _
                    sizeTb() as REG_SIZEMASK _
            )
    
    declare sub sregInitClass _
            ( _
                    byval this_ as REGCLASS ptr, _
                    sizeTb() as REG_SIZEMASK _
            )
    
    '':::::
    function regNewClass _
            ( _
                    byval class_ as integer, _
                    byval regs as integer, _
                    sizeTb() as REG_SIZEMASK, _
                    byval isstack as integer _
            ) as REGCLASS ptr
    
        dim as REGCLASS ptr this_
    
            this_ = callocate( len( REGCLASS ) )
    
            this_->class = class_
            this_->regs = regs
            this_->isstack = isstack
    
            if( this_->isstack = FALSE ) then
                    regInitClass( this_, sizeTb() )
            else
                    sregInitClass( this_, sizeTb() )
            end if
    
            function = this_
    
    end function
    
    '':::::
    function regDelClass _
            ( _
                    byval this_ as REGCLASS ptr _
            ) as integer
    
            function = FALSE
    
            if( this_ = NULL ) then
                    exit function
            end if
    
            deallocate( this_ )
    
            function = TRUE
    
    end function
    Thanks in advance to any help !
    ClŠudio

  2. #2
    pwning noobs Zlatko's Avatar
    Join Date
    Jun 2009
    Location
    The Great White North
    Posts
    132
    Hello ClŠudio
    Please confirm. Do you want this translated to C or C++, because it looks like you're dealing with classes here. Assuming you want strictly C, we can declare REGCLASS as a struct with elements mentioned in regNewClass. In the code below, see if you can follow the mapping from BASIC to C. Please ask questions about what you don't understand. I don't know what REG_SIZEMASK is so I made it an array of 10 integers to allow the code to compile. Now its your turn.

    Code:
    #include <stdlib.h> /* needed for malloc */
    
    typedef int REG_SIZEMASK[10];
    
    typedef struct 
    {
    	int regs;
    	int isStack;
    } RegClass;
    
    void regInitClass(RegClass* theRegClass, REG_SIZEMASK sizeTb)
    {
    	/* TODO */
    }
    
    void sregInitClass(RegClass* theRegClass, REG_SIZEMASK sizeTb)
    {
    	/* TODO */
    }
    
    
    RegClass* regNewClass(int regs, REG_SIZEMASK sizeTb, int isstack)
    {
    	RegClass* theRegClass = (RegClass*)malloc(sizeof(RegClass));
    	theRegClass->regs = regs;
    	theRegClass->isStack = isstack;
    
    	if ( ! theRegClass->isStack)
    	{
    		regInitClass(theRegClass, sizeTb);
    	}
    	else
    	{
    		sregInitClass(theRegClass, sizeTb);
    	}
    
    	return theRegClass;
    }
    
    int regDelClass(RegClass* theRegClass)
    {
    	if (theRegClass == NULL)
    	{
    		return 0;
    	}
    	free(theRegClass);
    	return 1;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [ANN] New script engine (Basic sintax)
    By MKTMK in forum C++ Programming
    Replies: 1
    Last Post: 11-01-2005, 09:28 AM
  2. what are your thoughts on visual basic?
    By orion- in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 09-22-2005, 04:28 AM
  3. visual basic vs C or C++
    By FOOTOO in forum Windows Programming
    Replies: 5
    Last Post: 02-06-2005, 07:41 PM
  4. Basic to C++ Translation
    By emus21 in forum C++ Programming
    Replies: 9
    Last Post: 06-26-2003, 07:15 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21