Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Official C Challenge ①

Name: Anonymous 2010-07-18 12:23

Task:  Come up with an extension to the C programming language.  Provide a clear description of the extension, and a code sample that clearly shows what the extension is intended to do.

Prize:  (Winning criteria are not specified.)  The winner will have his extension featured in the C11 language standard.

My entry:  ... Sorry, I think C is perfect in every way already.

Name: Anonymous 2010-07-18 12:26

>>1
My entry:  ... Sorry, I think C is perfect in every way already.

YOU WIN

Name: Anonymous 2010-07-18 12:38

Do small cosmetic changes count?

Name: Anonymous 2010-07-18 12:46

>>3
If you put lipstick on pig its still a pig.

Name: Anonymous 2010-07-18 12:56

My entry has unfortunately been preempted by Cilk.

Name: Bjarne 2010-07-18 13:08

My entry: C++

Name: Niklaus 2010-07-18 13:25

My entry: Pascal

Name: Anonymous 2010-07-18 13:28

Unary Operators

unary-expression:
   postfix-expression
   ++ unary-expression
   -- unary-expression
   unary-operator cast-expression
   sizeof unary-expression
   sizeof [i]( type-name )
   hax unary-anus-expression

The hax operator haxes its operand, which may be an unary-anus-expression.

Name: Anonymous 2010-07-18 14:01

inline C++

Name: Anonymous 2010-07-18 14:20

>>4
But at least it has nicer looking lips!

Name: Anonymous 2010-07-18 14:20

inline perl:
int main(void)
{ int a = 23, b = 19;
  int c = __perl($, $$, pop + pop)(a, b);
  char *s = __perl($, $$, pop + pop)(a, b);
  printf("%d + %d =\n"
         " int: %d\n"
         " string: %s\n",
         a, b, c, s);
  return 0; }


output:
23 + 19 =
 int: 42
 string: 42

Name: Anonymous 2010-07-18 14:34

>>11
also,
int main(void)
{ int a = 23, b = 19;
  printf("%d + %d =\n"
         " int: %d\n"
         " string: %s\n",
         a, b,
         __perl($, $$, pop + pop)(a, b),
         __perl($, $$, pop + pop)(a, b));
  return 0; }

produces the same output.

Name: Anonymous 2010-07-18 15:19

>>5
+1 for cleverness.

Name: Anonymous 2010-07-18 16:12

Here's a crazy idea I had, but it doesn't need any extensions:

union {
    void* pointer;
    struct {
        unsigned int address : 48;
        unsigned int extra   : 16;
    } details;
};


Hope I got the values in the right order ...

Name: Anonymous 2010-07-18 16:16

>>14
two words: middle endian.

Name: Anonymous 2010-07-18 16:43

>>15
Eggs don't have a middle end, or am I missing something?

Name: Anonymous 2010-07-18 16:44

Name: Anonymous 2010-07-18 16:46

>>16
You're missing the metaphor.

Name: Anonymous 2010-07-18 16:47

The middle-endian name makes no sense.

Name: Anonymous 2010-07-18 16:50

>>19
It makes about as much sense as the common US and Europeon date formats.

Name: Anonymous 2010-07-18 16:50

Omelette-endian.

Name: Anonymous 2010-07-18 16:51

>>20
The common European format makes sense, it's just not the most convenient way to format dates.

Name: Anonymous 2010-07-18 16:52

>>20
Europeon date formats
What doesn't make sense about DD/MM/YYYY ?

Name: Anonymous 2010-07-18 16:57

>>23
It's backwards.

Name: Anonymous 2010-07-18 17:00

>>22

18-07-2010 16:51:31
          ^ Endianness changes here!

Name: Anonymous 2010-07-18 17:39

>>25
That's not a date format, that's a datetime format.

Name: Anonymous 2010-07-18 21:06

My entry:

Meta-C  (That name is probably already taken)

A built-in scripting language that runs, effectively, as a precompile step.  In otherwords


myfile.metac -> script parser -> myfile.c -> normal C compiler -> etc...


The scripting language might be Perl-like or Python-like, I don't know, but it just needs to be something modern with nice regular expression support.

The script delimiters are /@ and @/.

Example of what you could do:

myfile.metac

#include <stdio.h>

int main(int, char**)
{

  /@
    # (Assuming perl is the embedded language)
    my $n = 5;
    foreach my $i (1 .. $n)
    {
  @/
      printf("this line prints /@$n@/ times, this is time number /@$i@/\n");

  /@
    }
  @/

  return 0;
}


The script parser would expand that to

myfile.c

#include <stdio.h>

int main(int, char**)
{
      printf("this line prints 5 times, this is time number 1\n");

  return 0;
}


This is a pretty trivial example but the concept is very powerful.  You implement most of C++ manually in this way, since nearly everything C++ adds to C is just compile-time crap.  But the bonus would be that you would be in control of how things behave, instead of the C++ compiler.

Name: Anonymous 2010-07-18 21:07

ISO 8601 BITCH

Name: Anonymous 2010-07-18 21:08

>>27
Fuck.

The correct expansion would be


#include <stdio.h>

int main(int, char**)
{
      printf("this line prints 5 times, this is time number 1\n");
      printf("this line prints 5 times, this is time number 2\n");
      printf("this line prints 5 times, this is time number 3\n");
      printf("this line prints 5 times, this is time number 4\n");
      printf("this line prints 5 times, this is time number 5\n");

  return 0;
}

Name: Anonymous 2010-07-18 21:10

>>27
You know you can inline C with Perl, right?

Name: Anonymous 2010-07-18 21:11

>>27
Still doing string substitution in this day and age?
I'd imagine we'd be past that and started doing AST manipulations instead!

Name: Anonymous 2010-07-18 21:21

>>30
You mean like with a heredoc?  That's a perl file with C in it.  This is a C file with perl in it.  Subtle difference, maybe.  I like this way better and I think this is more readable.  It still looks like C.

Name: Anonymous 2010-07-18 21:37

>>32
It still looks like C.
From a bird's eye view it looks more like PHP. By the way, it's not a "C file" -- at least not yet. How can you say you like it better when you aren't even aware of the endless alternatives?

You mean like with a heredoc?
I was thinking of Inline::C but there are many many other methods. If you want a solution nearly as bad as yours I'm sure there's something to be found in Acme. There are also proper pre-processor tools that do what you suggest although, again, not as badly as you'd prefer.

Name: Anonymous 2010-07-18 21:41

i think it would be cool for c to have python variables like lists and dictonarys also indentatin syntax would be nice :)

Name: Anonymous 2010-07-18 21:41

i think it would be cool for c to have python variables like lists and dictonarys also indentatin syntax would be nice :)

Name: Anonymous 2010-07-18 21:42

Listen guys, If nobody's interested in my hax operator, then maybe i'll just leave /prog/ and not come back!!!

Name: Anonymous 2010-07-18 21:56

>>36
Bye.

Name: Anonymous 2010-07-18 22:00

>>36
Make that TWO!

Name: Anonymous 2010-07-18 22:10

>>38
THREE now!


Actually just two because I am >>36 :'(

Name: Anonymous 2010-07-18 23:18

>>33
From a bird's eye view it looks more like PHP.
Yeah, that's actually what gave me the idea.

By the way, it's not a "C file"
Yes it is.  The OP's post was about extensions to the C language.  If this became an extension, then this is what a C file would look like.

There are also proper pre-processor tools that do what you suggest
Really?  Like what?  I'm genuinely interested.

a solution nearly as bad as yours
You're so deep.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List