Thread: pre-compiler

  1. #1
    null pointer Structure's Avatar
    Join Date
    May 2019
    Posts
    148

    Post pre-compiler

    What is it?

    It is HyperC. This is a pre-compiler for c developers. It was designed for experienced c developers or people who code a lot. The idea behind the compiler is to streamline common tasks in c. The c language is old and can be very confusing and complicated at times. HyperC aims to solve those two problems.

    Why use it?

    If you have coded 10, 100 or even 1000 programs you know that typing the same things can become redundant. HyperC eliminates this redundancy and minimizes build time.

    How can i use?

    You can find it here: Hyper C Compiler.
    It is currently only available as a windows executable but has no specific windows dependency. It is one file you can download and execute from the command line.

    How can i compile a HyperC application?

    HyperC was designed for the c developer. That being said you should already know how to compile a c application. Also why i'm exclusively putting details out on this forum.

    A HyperC application can have any extension. The preferred extension is .hcc as it's easy to tell what the app is for.

    HyperC command line compilation:
    Code:
    hcc filename.hcc output.c
    Example "Hello World"
    Code:
    <stdio.h>;
    @{
      ink "Hello World.";
    };
    more information and examples can be found here: HyperC


  2. #2
    null pointer Structure's Avatar
    Join Date
    May 2019
    Posts
    148

    Thumbs up HyperC Extended Example

    recursive rendering:

    Code:
    <stdio.h>;<string.h>;<stdlib.h>;
    
    // string comparison function ;
    #@compare($*string1,$*string2) {
      #response = 1;
      loop 0 to strlen(string1) as i {
        case string1[i] != string2[i] {
          response = 0;
        };
      };
      return response;
    };
    
    // entry function ;
    @{
      app: {
        ink "::_ "; get input[10];
        case compare(input,"exit") {
          run exit;
        };
        run app;
      };
      exit: {
        ink "Exited.";
        exit(1);
      };
    };
    Last edited by Structure; 09-15-2019 at 05:28 PM.


  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,267
    This looks like it has an out of bounds access bug:
    Code:
    // string comparison function ;
    int compare($*string1,$*string2) {
      #response = 1;
      loop 0 to strlen(string1) as i {
        case string1[i] != string2[i] {
          response = 0;
        };
      };
      return response;
    };
    Basically, when strlen(string1) > strlen(string2), the loop will compare characters from string2 that don't exist.

    Looking at this code:
    Code:
    // entry function ;
    @{
      app: {
        ink "::_ "; get input[10];
        case compare(input,"exit") {
          run exit;
        };
        run app;
      };
      exit: {
        ink "Exited.";
        exit(1);
      };
    };
    run looks like goto by another name.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    null pointer Structure's Avatar
    Join Date
    May 2019
    Posts
    148
    run looks like goto by another name.
    It is.

    Code:
    int compare($*string1,$*string2) { }
    should be
    Code:
    #@compare($*string1,$*string2) { }
    or
    Code:
    int compare(char *string1,char *string2) { }
    The @ allows for $ as char.
    Last edited by Structure; 09-15-2019 at 05:32 PM.


  5. #5
    null pointer Structure's Avatar
    Join Date
    May 2019
    Posts
    148
    when strlen(string1) > strlen(string2), the loop will compare characters from string2 that don't exist
    I'm not having any issues.


  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,267
    Quote Originally Posted by Structure
    I'm not having any issues.
    So how does HyperC handle the issue?

    It's a logic error. Your logic is simply wrong, so if you're not having any issues, then either you wrote HyperC to handle this somehow, or you didn't and you're looking at the effects of undefined behaviour: your mistake is hidden because the compiler generated code that appears to work when it doesn't.

    EDIT:
    Oh, I'm mistaken: the out of bounds comparison doesn't happen because it's saved by string2 being null terminated causing loop termination just in time.
    Last edited by laserlight; 09-15-2019 at 05:51 PM.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    null pointer Structure's Avatar
    Join Date
    May 2019
    Posts
    148

    Post HyperC

    your mistake is hidden because the compiler generated code that appears to work when it doesn't.
    Code:
    /* compiled with HYPER C v4.2.4 */
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    int compare(char *string1,char *string2) {
    int response = 1;
    for (int i=0;i<=strlen(string1);i++) {
    if ( string1[i] != string2[i] ) {
    response = 0;
    };
    };
    return response;
    };
    int main(int argc, char *argv[]) {
    app: {
    printf("\n::_ ");
    char  input[10];
    fgets( input,sizeof( input)/sizeof( input[0]),stdin); 
    input[strlen( input)-1] = 0;
    if ( compare(input,"exit") ) {
    goto exit;
    };
    goto app;
    };
    exit: {
    printf("Exited.");
    exit(1);
    };
    return 0;};
    Last edited by Structure; 09-15-2019 at 05:43 PM.


  8. #8
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,523
    I expect the code in post #7 has the exact error being pointed out

    Code:
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    int compare(char *string1,char *string2) {
    int response = 1;
    for (int i=0;i<=strlen(string1);i++) {
        printf("Comparing '%c' and '%c'\n", string1[i], string2[i]);
    if ( string1[i] != string2[i] ) {
    response = 0;
    };
    };
    return response;
    };
    
    int main(void)
    {
        char *s1 = "123456";    // These should be const char but compare() is not
        char *s2 = "ABC";       // const correct and I don't want to cast
    
        if (!compare(s1,s2))
            printf("wtf Strings are not equal\n");
        return 0;
    }
    Output:
    Code:
    Comparing '1' and 'A'
    Comparing '2' and 'B'
    Comparing '3' and 'C'
    Comparing '4' and ''
    Comparing '5' and 'w'
    Comparing '6' and 't'
    Comparing '' and 'f'
    Edit:
    Perhaps this is a better example
    Code:
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    int compare(char *string1,char *string2) {
    int response = 1;
    for (int i=0;i<=strlen(string1);i++) {
        printf("Comparing '%c' and '%c'\n", string1[i], string2[i]);
    if ( string1[i] != string2[i] ) {
    response = 0;
    };
    };
    return response;
    };
    
    int main(void)
    {
        char *s1 = "123456";
        char *s2 = malloc(2);
        
        if (!s2) goto end;
        
        strcpy (s2, "A");
         
        if (!compare(s1,s2))
            printf("!=\n");
    
    end:
        free(s2);
        return 0;
    }
    Code:
    valgrind ./a.out 
    ==2605== Memcheck, a memory error detector
    ==2605== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
    ==2605== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
    ==2605== Command: ./a.out
    ==2605== 
    Comparing '1' and 'A'
    Comparing '2' and ''
    ==2605== Invalid read of size 1
    ==2605==    at 0x401194: compare (hyper.c:7)
    ==2605==    by 0x40124E: main (hyper.c:24)
    ==2605==  Address 0x4a2b042 is 0 bytes after a block of size 2 alloc'd
    ==2605==    at 0x483880B: malloc (vg_replace_malloc.c:309)
    ==2605==    by 0x401227: main (hyper.c:18)
    ==2605== 
    Comparing '3' and ''
    ==2605== Invalid read of size 1
    ==2605==    at 0x4011DB: compare (hyper.c:8)
    ==2605==    by 0x40124E: main (hyper.c:24)
    ==2605==  Address 0x4a2b042 is 0 bytes after a block of size 2 alloc'd
    ==2605==    at 0x483880B: malloc (vg_replace_malloc.c:309)
    ==2605==    by 0x401227: main (hyper.c:18)
    ==2605==
    Last edited by Hodor; 09-15-2019 at 06:36 PM.

  9. #9
    null pointer Structure's Avatar
    Join Date
    May 2019
    Posts
    148
    compare.hcc
    Code:
    #@compare($*string1,$*string2) {
      #response = 1; 
      case strlen(string1) != strlen(string2) {
        response = 0;
      } else {
       loop 0 to strlen(string1) as i {
        case string1[i] != string2[i] {
          response = 0;
        };
       };
      };
      return response;
    };
    compare.c
    Code:
    int compare(char *string1,char *string2) {
      int response = 1;
      if ( strlen(string1) != strlen(string2) ) {
        response = 0;
      } else {
        for (int i=0;i<=strlen(string1);i++) {
          if ( string1[i] != string2[i] ) {
            response = 0;
          };
        };
      };
      return response;
    };
    Last edited by Structure; 09-15-2019 at 06:45 PM.


  10. #10
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,523
    Quote Originally Posted by Structure View Post
    compare.hcc
    Code:
    #@compare($*string1,$*string2) {
      #response = 1; 
      case strlen(string1) != strlen(string2) {
        response = 0;
      } else {
       loop 0 to strlen(string1) as i {
        case string1[i] != string2[i] {
          response = 0;
        };
       };
      };
      return response;
    };
    compare.c
    Code:
    int compare(char *string1,char *string2) {
      int response = 1;
      if ( strlen(string1) != strlen(string2) ) {
        response = 0;
      } else {
        for (int i=0;i<=strlen(string1);i++) {
          if ( string1[i] != string2[i] ) {
            response = 0;
          };
        };
      };
      return response;
    };
    Ok, so you've updated it since post #7 but now it's inefficient.

  11. #11
    null pointer Structure's Avatar
    Join Date
    May 2019
    Posts
    148
    so you've updated it since post #7
    I feel like you are missing the point.

    you're looking at the effects of undefined behaviour
    I'm starting to grasp this concept a little better.
    Last edited by Structure; 09-16-2019 at 06:54 AM.


  12. #12
    null pointer Structure's Avatar
    Join Date
    May 2019
    Posts
    148

    Thumbs up HyperC tips...

    How can i import another file ?

    Imo there are many reasons to use the compiler.
    One of the best features in hyperC is file injection:

    Code:
    :>filename.hcc;
    Last edited by Structure; 09-16-2019 at 08:08 AM.


  13. #13
    null pointer Structure's Avatar
    Join Date
    May 2019
    Posts
    148

    Lightbulb HyperC tips...

    Object Structures

    Code:
    <stdio.h>; <string.h>;
    
    person! {
      name! {
        char first[15];
        char last[15];
      };
      int id;
    };
    
    @{
      person1 = !person;
      
      with person1.name.;
        first = "John"; last = "Doe";
      with ink ;
        "Hello " [s]person1.name.first " ";
        [s]person1.name.last ".\n";
      with;
    };
    Last edited by Structure; 09-16-2019 at 12:17 PM.


  14. #14
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,267
    You're posting pretty much the same thing as your other thread.

    * thread closed *
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 04-23-2012, 07:54 AM
  2. Replies: 7
    Last Post: 12-13-2010, 10:02 PM
  3. Replies: 4
    Last Post: 09-12-2009, 01:10 PM
  4. Replies: 2
    Last Post: 02-04-2008, 02:34 AM
  5. hp iPAQ 6300 && C compiler || C# compiler
    By xddxogm3 in forum Tech Board
    Replies: 2
    Last Post: 12-07-2004, 07:28 AM

Tags for this Thread