From d9f64c94bf5353033db6bf588ebe23550941b10b Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sun, 9 Oct 2011 14:52:58 +0200 Subject: [PATCH] simple demo using a pointer and a struct --- src/tool/try.cpp | 67 +++++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/src/tool/try.cpp b/src/tool/try.cpp index bdfca7100..9e68a90a5 100644 --- a/src/tool/try.cpp +++ b/src/tool/try.cpp @@ -19,52 +19,55 @@ // 1/11 - exploring numeric limits // 1/11 - integer floor and wrap operation(s) // 1/11 - how to fetch the path of the own executable -- at least under Linux? - - -#include +// 10/11 - simple demo using a pointer and a struct #include -#include -extern "C" { -#include -} -#include "lib/error.hpp" -#include "lib/symbol.hpp" - - -using std::string; using std::cout; -using std::endl; -using lib::Literal; -using lib::STRING_MAX_RELEVANT; -namespace error = lumiera::error; -Literal GET_PATH_TO_EXECUTABLE ("/proc/self/exe"); -string -catchMyself () -{ - string buff(STRING_MAX_RELEVANT+1, '\0' ); - ssize_t chars_read = readlink (GET_PATH_TO_EXECUTABLE, &buff[0], STRING_MAX_RELEVANT); - - if (0 > chars_read || chars_read == ssize_t(STRING_MAX_RELEVANT)) - throw error::Fatal ("unable to discover path of running executable"); - - buff.resize(chars_read); - return buff; -} +/** + * custom datastructure + * holding a constant char array with "hey" + */ +struct MyStruct + { + char data_[3]; + const int length_; + + MyStruct() + : length_(3) + { + const char *tmp = "hey"; + for (int i=0; ilength_; ++i) + cout << myPointer->data_[i]; + + cout << "\n"; + } + int main (int, char**) //(int argc, char* argv[]) { + printMyStruct (&theStruct); - NOBUG_INIT; - - cout << "\n\nwho am I? :" << catchMyself(); cout << "\n.gulp.\n"; return 0;