Author Topic: C Basic Class Library  (Read 65675 times)

Offline AIR

  • BASIC Developer
  • Posts: 932
  • Coder
Re: C Basic Class Library
« Reply #15 on: November 11, 2013, 07:57:22 PM »
c11 didn't really become available until gcc 4.7.

What versions are those systems running?  gcc --version (just need the version, not all of the output, thanks.)

My C9 instance report 4.4.7.


kryton9

  • Guest
Re: C Basic Class Library
« Reply #16 on: November 11, 2013, 09:31:37 PM »
Windows 7 output works fine. Lots of warnings however. Just copy what is listed in tiny size and paste in text editor, will be correct size then.
Quote
mingw32-gcc.exe -Wall  -O2     -c D:\8gb\CBasicClassLibrary\cp\Test.c -o obj\Release\Test.o
In file included from D:\8gb\CBasicClassLibrary\cp\BasicClassLibrary.h:9:0,
                 from D:\8gb\CBasicClassLibrary\cp\Test.c:3:
D:\8gb\CBasicClassLibrary\cp\StringClass.c: In function 'StringFreeN':
D:\8gb\CBasicClassLibrary\cp\StringClass.c:137:5: warning: statement with no effect [-Wunused-value]
D:\8gb\CBasicClassLibrary\cp\StringClass.c: In function 'StringSplit':
D:\8gb\CBasicClassLibrary\cp\StringClass.c:398:7: warning: implicit declaration of function 'StringInstr' [-Wimplicit-function-declaration]
D:\8gb\CBasicClassLibrary\cp\StringClass.c: In function 'StringInsert':
D:\8gb\CBasicClassLibrary\cp\StringClass.c:600:9: warning: unused variable 'w' [-Wunused-variable]
D:\8gb\CBasicClassLibrary\cp\StringClass.c: In function 'StringDelete':
D:\8gb\CBasicClassLibrary\cp\StringClass.c:614:9: warning: unused variable 'w' [-Wunused-variable]
In file included from D:\8gb\CBasicClassLibrary\cp\BasicClassLibrary.h:10:0,
                 from D:\8gb\CBasicClassLibrary\cp\Test.c:3:
D:\8gb\CBasicClassLibrary\cp\LexiClass.c: In function 'WordInfo':
D:\8gb\CBasicClassLibrary\cp\LexiClass.c:50:5: warning: format '%i' expects argument of type 'int', but argument 2 has type 'char *' [-Wformat]
D:\8gb\CBasicClassLibrary\cp\LexiClass.c:51:5: warning: format '%i' expects argument of type 'int', but argument 2 has type 'char *' [-Wformat]
D:\8gb\CBasicClassLibrary\cp\LexiClass.c:52:5: warning: format '%i' expects argument of type 'int', but argument 2 has type 'char *' [-Wformat]
D:\8gb\CBasicClassLibrary\cp\Test.c: At top level:
D:\8gb\CBasicClassLibrary\cp\Test.c:5:12: warning: return type defaults to 'int' [-Wreturn-type]
D:\8gb\CBasicClassLibrary\cp\Test.c: In function 'main':
D:\8gb\CBasicClassLibrary\cp\Test.c:81:3: warning: control reaches end of non-void function [-Wreturn-type]
D:\8gb\CBasicClassLibrary\cp\Test.c: In function 'TestStrings':
D:\8gb\CBasicClassLibrary\cp\Test.c:75:3: warning: control reaches end of non-void function [-Wreturn-type]
In file included from D:\8gb\CBasicClassLibrary\cp\BasicClassLibrary.h:10:0,
                 from D:\8gb\CBasicClassLibrary\cp\Test.c:3:
D:\8gb\CBasicClassLibrary\cp\Test.c: In function 'EndLine':
D:\8gb\CBasicClassLibrary\cp\LexiClass.c:159:3: warning: control reaches end of non-void function [-Wreturn-type]
D:\8gb\CBasicClassLibrary\cp\Test.c: In function 'NextSpace':
D:\8gb\CBasicClassLibrary\cp\LexiClass.c:142:3: warning: control reaches end of non-void function [-Wreturn-type]
D:\8gb\CBasicClassLibrary\cp\Test.c: In function 'WordShow':
D:\8gb\CBasicClassLibrary\cp\LexiClass.c:60:3: warning: control reaches end of non-void function [-Wreturn-type]
D:\8gb\CBasicClassLibrary\cp\Test.c: In function 'WordInfo':
D:\8gb\CBasicClassLibrary\cp\LexiClass.c:53:3: warning: control reaches end of non-void function [-Wreturn-type]
In file included from D:\8gb\CBasicClassLibrary\cp\BasicClassLibrary.h:9:0,
                 from D:\8gb\CBasicClassLibrary\cp\Test.c:3:
D:\8gb\CBasicClassLibrary\cp\Test.c: In function 'StringAsc':
D:\8gb\CBasicClassLibrary\cp\StringClass.c:671:3: warning: control reaches end of non-void function [-Wreturn-type]
D:\8gb\CBasicClassLibrary\cp\Test.c: In function 'StringShow':
D:\8gb\CBasicClassLibrary\cp\StringClass.c:655:3: warning: control reaches end of non-void function [-Wreturn-type]
In file included from D:\8gb\CBasicClassLibrary\cp\BasicClassLibrary.h:7:0,
                 from D:\8gb\CBasicClassLibrary\cp\Test.c:3:
D:\8gb\CBasicClassLibrary\cp\Test.c: In function 'NewObject':
D:\8gb\CBasicClassLibrary\cp\GenericClass.c:200:3: warning: control reaches end of non-void function [-Wreturn-type]
D:\8gb\CBasicClassLibrary\cp\Test.c: In function 'Truncate':
D:\8gb\CBasicClassLibrary\cp\GenericClass.c:183:3: warning: control reaches end of non-void function [-Wreturn-type]
D:\8gb\CBasicClassLibrary\cp\Test.c: In function 'Shrink':
D:\8gb\CBasicClassLibrary\cp\GenericClass.c:171:3: warning: control reaches end of non-void function [-Wreturn-type]
D:\8gb\CBasicClassLibrary\cp\Test.c: In function 'Stretch':
D:\8gb\CBasicClassLibrary\cp\GenericClass.c:159:3: warning: control reaches end of non-void function [-Wreturn-type]
In file included from D:\8gb\CBasicClassLibrary\cp\BasicClassLibrary.h:9:0,
                 from D:\8gb\CBasicClassLibrary\cp\Test.c:3:
D:\8gb\CBasicClassLibrary\cp\StringClass.c: In function 'StringFreeN':
D:\8gb\CBasicClassLibrary\cp\StringClass.c:134:23: warning: 'i' may be used uninitialized in this function [-Wuninitialized]
mingw32-g++.exe  -o bin\Release\cp.exe obj\Release\Test.o   -s 
Output size is 17.50 KB
Process terminated with status 0 (0 minutes, 3 seconds)
0 errors, 21 warnings (0 minutes, 3 seconds)
« Last Edit: November 11, 2013, 09:51:31 PM by kryton9 »

kryton9

  • Guest
Re: C Basic Class Library
« Reply #17 on: November 11, 2013, 09:37:05 PM »
Charles,

I'm working on getting the modified version of your code working on C9 and Red Hat is complaining on the run but not the compile.

allbasic@c_basic:~/668428/usr/john/cbc $ ./t_cbc
./t_cbc: error while loading shared libraries: __vdso_time: invalid mode for dlopen(): Invalid argument
allbasic@c_basic:~/668428/usr/john/cbc $

The same code runs fine on Ubuntu 64 bit.

John

I posted the same problem on c9 Blog a few days ago. From what I read, it is having conflicting versions of the same libs.

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: C Basic Class Library
« Reply #18 on: November 11, 2013, 09:52:01 PM »
Quote
I posted the same problem on c9 Blog a few days ago. From what I read, it is having conflicting versions of the same libs.

Charles only posted the his code here today so I'm not sure what you're saying.

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: C Basic Class Library
« Reply #19 on: November 11, 2013, 11:05:59 PM »
I was able to get all the .c source files fixed so CINT could run Charles new update. This is what CINT is saying ...

Code: [Select]
allbasic@c_basic:~/668428/usr/john/cbc $ cint -p Test.c
Warning: Automatic variable Free is allocated FILE:StringClass.c LINE:884
Warning: Automatic variable FreeN is allocated FILE:StringClass.c LINE:885
Warning: Automatic variable ArrayFree is allocated FILE:StringClass.c LINE:886
Warning: Automatic variable Copy is allocated FILE:StringClass.c LINE:887
Warning: Automatic variable GetChars is allocated FILE:StringClass.c LINE:888
Warning: Automatic variable SetChars is allocated FILE:StringClass.c LINE:889
Warning: Automatic variable GetMid is allocated FILE:StringClass.c LINE:890
Warning: Automatic variable SetMid is allocated FILE:StringClass.c LINE:891
Warning: Automatic variable Join is allocated FILE:StringClass.c LINE:893
Warning: Automatic variable Merge is allocated FILE:StringClass.c LINE:894
Warning: Automatic variable Split is allocated FILE:StringClass.c LINE:895
Warning: Automatic variable Repeat is allocated FILE:StringClass.c LINE:896
Warning: Automatic variable Replace is allocated FILE:StringClass.c LINE:897
Warning: Automatic variable Ucase is allocated FILE:StringClass.c LINE:898
Warning: Automatic variable Lcase is allocated FILE:StringClass.c LINE:899
Warning: Automatic variable Ltrim is allocated FILE:StringClass.c LINE:900
Warning: Automatic variable Rtrim is allocated FILE:StringClass.c LINE:901
Warning: Automatic variable Trim is allocated FILE:StringClass.c LINE:902
Warning: Automatic variable Insert is allocated FILE:StringClass.c LINE:903
Warning: Automatic variable Delete is allocated FILE:StringClass.c LINE:904
Warning: Automatic variable Chr is allocated FILE:StringClass.c LINE:905
Warning: Automatic variable Str is allocated FILE:StringClass.c LINE:906
Warning: Automatic variable Show is allocated FILE:StringClass.c LINE:907
Warning: Automatic variable Asc is allocated FILE:StringClass.c LINE:908
Warning: Automatic variable Cmp is allocated FILE:StringClass.c LINE:909
Warning: Automatic variable Instr is allocated FILE:StringClass.c LINE:910
Warning: Automatic variable Val is allocated FILE:StringClass.c LINE:911
Error: illegal pointer to class object vo 0x0 11  FILE:Test.c LINE:14
!!! return from main() function

cint>
« Last Edit: November 11, 2013, 11:08:18 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: C Basic Class Library
« Reply #20 on: November 12, 2013, 12:11:47 AM »
Something very strange is going on with C9. I'm getting the same error with my C BASIC simple demo. This compiled fine before. CINT isn't having a problem with it. ???

Code: [Select]
allbasic@c_basic:~/668428/usr/john/cintbasic $ ./cb
./cb: error while loading shared libraries: __vdso_time: invalid mode for dlopen(): Invalid argument
allbasic@c_basic:~/668428/usr/john/cintbasic $

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: C Basic Class Library
« Reply #21 on: November 12, 2013, 12:26:09 AM »
The All BASIC C9 workspace is hosed. I went to another workspace and my cb.c example compile with gcc. I then tried Charles new class example.

Code: [Select]
scriptbasic@c9basic:~/642383/cbasic $ gcc Test.c -o teat1
In file included from BasicClassLibrary.h:9,
                 from Test.c:3:
StringClass.c:878: error: redefinition of typedef ‘StringClassTable’
StringClass.c:4: note: previous declaration of ‘StringClassTable’ was here
StringClass.c:878: error: redefinition of typedef ‘StringMethods’
StringClass.c:4: note: previous declaration of ‘StringMethods’ was here
scriptbasic@c9basic:~/642383/cbasic $ ./cb
1
2
3
4
5
x is now 6
My guess is 6
6
Double it up
scriptbasic@c9basic:~/642383/cbasic $

I tried both cb.c and Test.c on WinXP (VirtualBox) with MinGW32 (gcc version 4.7.1 (tdm-1)) and it worked without issue.



Here is CINT under WinXP.


« Last Edit: November 12, 2013, 01:07:31 AM by John »

Offline Charles Pegge

  • BASIC Developer
  • Posts: 69
Re: C Basic Class Library
« Reply #22 on: November 12, 2013, 01:36:29 AM »
Thank you all for testing :)

I believe most of the problems are with line 4 in StringClass:

typedef struct StringClassTableStruct StringClassTable,*StringMethods;


It is a forward declaration for the ClassTable structure, which is defined following all the methods

I am using GCC 4.7.0

If this kind of declaration is unsupported by other versions of C then there is a compromise: make the String methods (void*) / ref

 class StringClassStruct
  begin
//BASE MEMBERS
  ref f;           // pointer to methods table
  int type;     // dynamic type code
  int offset;        // size of this header
  int nbytes;      // buffer ze for body of data
  int count;        // number of elements
  int size;           // size of each element
  end
  StringClass,*StringObject;


This compromises OOP notation, but its not serious, since it is generally more efficient to to work with dreferenced methods.

    ((StringMethods)vo->f)->Show(&vo); //ugh!

    dim as StringMethods f=vo->f; //methods

    f->SetChars(&uo,"LO");
...


I've update the zip here:
http://www.allbasic.info/forum/index.php?topic=283.msg3280#msg3280


Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: C Basic Class Library
« Reply #23 on: November 12, 2013, 01:51:20 AM »
Not there yet.

Code: [Select]
scriptbasic@c9basic:~/642383/cbclass $ gcc Test.c -o test
Test.c: In function ‘TestStrings’:
Test.c:14: warning: dereferencing ‘void *’ pointer
Test.c:14: error: request for member ‘Show’ in something not a structure or union
Test.c:15: warning: dereferencing ‘void *’ pointer
Test.c:15: error: request for member ‘SetChars’ in something not a structure or union
Test.c:16: warning: dereferencing ‘void *’ pointer
Test.c:16: error: request for member ‘SetChars’ in something not a structure or union
scriptbasic@c9basic:~/642383/cbclass $

Offline Charles Pegge

  • BASIC Developer
  • Posts: 69
Re: C Basic Class Library
« Reply #24 on: November 12, 2013, 02:13:19 AM »
Can you try altering the first 2 offending lines in test.c

  //((StringMethods)vo->f)->Show(&vo); //ugh!

    dim as StringMethods f=(StringMethods) vo->f; //methods


« Last Edit: November 12, 2013, 02:35:51 AM by Charles Pegge »

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: C Basic Class Library
« Reply #25 on: November 12, 2013, 02:40:09 AM »
Okay, I made the change.


    // dim as StringMethods f=vo->f; //methods
    dim as StringMethods f=(StringMethods) vo->f; //methods

Code: [Select]
scriptbasic@c9basic:~/642383/cbclass $ gcc Test.c -o test
Test.c: In function ‘TestStrings’:
Test.c:14: warning: dereferencing ‘void *’ pointer
Test.c:14: error: request for member ‘Show’ in something not a structure or union
Test.c:15: warning: dereferencing ‘void *’ pointer
Test.c:15: error: request for member ‘SetChars’ in something not a structure or union
Test.c:16: warning: dereferencing ‘void *’ pointer
Test.c:16: error: request for member ‘SetChars’ in something not a structure or union
scriptbasic@c9basic:~/642383/cbclass $

I don't think that changed anything.

I'm on chat if that would speed things along. (I'm fading fast 2:45 am here)
« Last Edit: November 12, 2013, 02:42:58 AM by John »

Offline Charles Pegge

  • BASIC Developer
  • Posts: 69
Re: C Basic Class Library
« Reply #26 on: November 12, 2013, 02:48:59 AM »
Which gcc are you using John? my 4.7.0 does not protest.

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: C Basic Class Library
« Reply #27 on: November 12, 2013, 02:51:29 AM »
I posted them here.

If works fine on Ubuntu. Only Red Hat / CentOS are complaining. AIR is having issue on OSX.
« Last Edit: November 12, 2013, 02:53:09 AM by John »

Offline Charles Pegge

  • BASIC Developer
  • Posts: 69
Re: C Basic Class Library
« Reply #28 on: November 12, 2013, 03:02:59 AM »
No further ideas here. Sleep well!

---

Does MacOsx or RedHat have problems with CRLF  (ascii 13,10) line formats?
« Last Edit: November 12, 2013, 03:10:24 AM by Charles Pegge »

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: C Basic Class Library
« Reply #29 on: November 12, 2013, 03:10:05 AM »
Here is the error report trying to compile it on Android. (with latest fix)