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

Pages: 1-

Is the C Preprocessor Turing complete?

Name: Anonymous 2009-07-07 2:16

Is the C preprocessor turing complete? Of course there are no #while loops or anything, but consider this:

"hax.h":
#if VALUE < 1
#define VALUE 1
#else
#include "hax.h"
#endif


Here, hax.h include itself, creating a loop. There isn't a way to pass a value to the included file, though.

Name: Anonymous 2009-07-07 2:33

I don't have a fucking clue. Why don't you try it?

Name: FrozenVoid 2009-07-07 3:02

I write now half of my 'inline functions' with preprocessor.
I don't know how turing complete it is, but its pretty useful.

___________________________________
http://xs135.xs.to/xs135/09042/av922.jpg
The perpetual stream of human nature is formed into ever-changing shallows, eddies, falls and pools by the land over which it passes.

Name: FrozenVoid 2009-07-07 3:08

>>1 "isn't a way to pass a value to the included file,"
#ifdef VALUE
#error VALUE is defined
#endif
____________________________________________
http://xs135.xs.to/xs135/09042/av922.jpg
That social order and control, structure of governance, social cohesion in states or organizations larger than face-to- face society depends on the nature of the technology of memory--both how it works and what it remembers... In short, what societies value is what they memorize, and how they memorize it, and who has access to its memorized form determines the structure of power that the society represents and acts from.

Name: Anonymous 2009-07-07 4:28

Name: FrozenVoid 2009-07-07 4:45

>>5
This "code" should in some seppled way replace  #define TINY_MAX_SIZE 3
 
To generate the tiny_size specializations using horizontal repetition, we might write the following:

#include <boost/preprocessor/repetition.hpp>
#include <boost/preprocessor/arithmetic/sub.hpp>
#include <boost/preprocessor/punctuation/comma_if.hpp>

#define TINY_print(z, n, data) data

#define TINY_size(z, n, unused)                                 \
  template <BOOST_PP_ENUM_PARAMS(n, class T)>                   \
  struct tiny_size<                                             \
      BOOST_PP_ENUM_PARAMS(n,T)                                 \
      BOOST_PP_COMMA_IF(n)                                      \
      BOOST_PP_ENUM(                                            \
          BOOST_PP_SUB(TINY_MAX_SIZE,n), TINY_print, none)      \
  >                                                             \
    : mpl::int_<n> {};

BOOST_PP_REPEAT(TINY_MAX_SIZE, TINY_size, ~)

#undef TINY_size
#undef TINY_print




__________________________________________
http://xs135.xs.to/xs135/09042/av922.jpg
When despotism has established itself for ages in a country, as in France, it is not in the person of the king only that it resides. It has the appearance of being so in show, and in nominal authority; but it is not so in practice and in fact. It has its standard everywhere. Every office and department has its despotism, founded upon custom and usage. Every place has its Bastille, and every Bastille its despot. The original hereditary despotism resident in the person of the king, divides and sub-divides itself into a thousand shapes and forms, till at last the whole of it is acted by deputation. This was the case in France; and against this species of despotism, proceeding on through an endless labyrinth of office till the source of it is scarcely perceptible, there is no mode of redress. It strengthens itself by assuming the appearance of duty, and tyrannises under the pretence of obeying.

Name: Anonymous 2009-07-07 4:47

[color=green]testan[/color]

Name: Anonymous 2009-07-07 4:51

they lied

Name: Anonymous 2009-07-07 4:54

There is x68 assembler written in cpp.

Name: Anonymous 2009-07-07 5:23

I remember an IOCCC entry that implemented an ALU in the preprocessor

Name: FrozenVoid 2009-07-07 5:26

>>10 http://www.ioccc.org/2004/vik2.c



____________________________________________
http://xs135.xs.to/xs135/09042/av922.jpg
It looks like a vortex -- a gateway into another dimension.

Name: Anonymous 2009-07-07 6:01

There isn't a way to pass a value to the included file, though.
There sort of is, by defining the value and then including the file you want it to be passed to.

/* hax.h */
#ifndef VALUE
# define VALUE 1
#else
# define VALUE VALUE + 1
# if VALUE < 6
#  include "hax.h"
# endif
#endif

Name: Anonymous 2009-07-10 3:36

>>12
that that will end up just defining VALUE as VALUE + 1, which isn't very useful.

Name: Anonymous 2009-07-10 10:06

>>13
Peano is crying

Name: Anonymous 2009-07-10 18:29

The specification for the C preprocessor isn't Touring Complete, but I wouldn't be surprised if any of the implementations were. Technical specifications aside, it seems quite reasonable to fully emulate a RMP using the C preprocessor. Assuming every file in the program represented a node in the RMP. We can in any file: increment a counter (variable) by one and jump to any other node including the current one (by including it), check if a variable is zero, and if so jump to another node, or decrease a variable and jump to another node.

Name: Anonymous 2009-07-10 22:25

I believe the real question is, is it touring complete?

Name: Anonymous 2009-07-10 22:44

>>15
what's RPM?

Name: Anonymous 2009-07-10 22:44

>>17
i mean RMP.

Name: Anonymous 2009-07-10 22:49

>>18
back to /CS101/ please.

Name: Anonymous 2010-12-08 12:36

OP here.

Name: Anonymous 2010-12-08 12:41

OP is a faggot.

Name: Anonymous 2010-12-08 16:50

>>21 is a faggot.

Name: Anonymous 2011-01-27 18:51

WARNING: NECROPOSTING

Current unixtime: 1296172324

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