User Profile

Collapse

Profile Sidebar

Collapse
tanvalley
tanvalley
Last Activity: Mar 16 '16, 02:10 PM
Joined: Jun 9 '12
Location: Toronto
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • tanvalley
    started a topic Bash Process Substitution

    Bash Process Substitution

    In this sequence at the command prompt
    Code:
    $ x=()
    $ { while read;  do  x+=("$REPLY"); done; } <<<"$(ls)"
    $ printf 'count=%d\n' ${#x[@]}
    count=432
    $ wc -l <(ls)
         432 /dev/fd/63
    $ 
    $ 
    $ { while read;  do  x+=("$REPLY"); done; } <(ls)
    -bash: syntax error near unexpected token `<(ls)'
    what causes the error noted?
    ...
    See more | Go to post

  • tanvalley
    replied to static assertion about inheritance
    in C
    When the entire statement is
    static_cast<B>( *static_cast<D* >(0));
    there is no generated code and no runtime reference to location 0, so actually it is pretty.

    Furthermore, the sequence
    T* pt = 0;
    S<N>* ps = pt;
    when it does compile, as it should all of the time when the classes are used correctly, will usually produce executable code unless optimised away and possible warnings about unused...
    See more | Go to post

    Leave a comment:


  • tanvalley
    replied to static assertion about inheritance
    in C
    I don't think I should have to justify my design to ask a simple question about static assertions, but here goes:

    I have a template class that a programmer (also me) uses directly in code:

    template<class T,class N> class R {
    ...
    }

    There's also a "service class" whose implementation is entirely hidden from the programmer:

    template<class N> class S;
    ...
    See more | Go to post

    Leave a comment:


  • tanvalley
    replied to static assertion about inheritance
    in C
    If casts are so bad way are there hundreds of them (over 700 on my system) in the distributed standard template library?
    See more | Go to post

    Leave a comment:


  • If you were to switch to a c++ compiler (and you can do this without changing to an obect-oriented design) then using the GNU compilers, you can include
    Code:
    const char* classname(void) {return __PRETTY_FUNCTION__; }
    in every structure of interest. Then call it (parameter.clas sname()) and parse out the stucture name (just before the ::).

    Your mileage may vary, depending on the compiler you're using, and it's not just a matter of changing...
    See more | Go to post

    Leave a comment:


  • tanvalley
    started a topic static assertion about inheritance
    in C

    static assertion about inheritance

    Is this the canonical way to make a static assertion that class D is derived from class B?
    Code:
    (B)(*(D*)(0));
    Or is there any reason to use static_casts instead?
    Code:
    static_cast<B>(*static_cast<D*>(0));
    Neither seems to generate any code, even at no optimisation.
    Both give the error message "error: no matching function for call to 'B::B(D&)'" when the assertion fails, and are silent otherwise....
    See more | Go to post

  • tanvalley
    replied to template friend classes
    in C
    I need a single instance of C<T1> to be accessible by B<T1,T2>::f1() and by B<T1,T3>::f1() . By naming the functions individually (in my real case there are more of them) I can allow all of the members of each B<T1,x> access to the internals of C<T1>. I don't want to change my privates.
    See more | Go to post

    Leave a comment:


  • tanvalley
    started a topic template friend classes
    in C

    template friend classes

    I'd like to avoid listing all the functions in a template class as friends by declaring the whole class as a friend, but...

    Code:
    template<class T1> class A;
    template<class T1, class T2> class B;
    
    template<class T1> class C {
    
          friend void A<T1>::f1(void);
          friend void A<T1>::f2(void);
          friend void A<T1>::f3(void);
    ...
    See more | Go to post

  • This all started with:
    (i) my expressed dislike of casts, and
    (ii) my search for a legal syntactic replacement for "(reinterpret_c ast<PARAMETER*> (0))->function" which somehow seems inelegant but also seems like a reasonable idiomatic way to refer to a non-static member in a place where NO DEREFERENCE IS MADE AT RUN TIME.

    I didn't expect a fundamentalist rant on the foolishness of casting or a lesson on...
    See more | Go to post

    Leave a comment:


  • Then, of course, in order to store the result of Get() I need a way in my template<Test> class to determine Test::Get()'s return type. Any hints?
    See more | Go to post

    Leave a comment:


  • I think casting a null pointer without actually dereferencing it in generated code ought to be an exception to your rule. There's no type safety issue here.

    I'm curious to learn how to remove the cast from this:
    Code:
    #include <iostream>
    using namespace std;
    
    struct Test {
      int i;
    };
    
    int main() {
      cout << "sizeof i is "<<sizeof ((Test*)(0))->i
    ...
    See more | Go to post

    Leave a comment:


  • The purpose of this base class is (i) to enforce the requirement that the template parameter class actually has a function named, in this example, "function" and (ii) to extract its return type for use in derived classes.

    I think it's reasonable to forgive the cast (and a simple C-style cast compiles here, using g++-4.2.1, with the same result) because it's in code that's used for type determination only and, as with traditional...
    See more | Go to post

    Leave a comment:


  • Why would I introduce a data member into a base class when all I want is a typedef?
    See more | Go to post

    Leave a comment:


  • tanvalley
    started a topic Get return type of function in template parameter
    in C

    Get return type of function in template parameter

    Is this really the preferred way to get the return type, for use in a derived class, of a function defined in the template parameter?

    Code:
    template<class PARAMETER> class C {
             protected:
                typedef typeof (reinterpret_cast<PARAMETER*>(0))->function() returntype;
          };
    This works just fine for me, but seems inelegant.
    See more | Go to post

  • tanvalley
    replied to integer constant expression
    in C
    Nothing... that was just a simple way of showing, in response to the first reply, that "abcd"[1] is *not* recognised (by gcc) as a constant integer expression. All this stuff is really in a too-complex-to-post-macro.

    Thanks for the detailed response.
    See more | Go to post

    Leave a comment:


  • tanvalley
    replied to integer constant expression
    in C
    when I compile
    Code:
      switch (0) {
          case 1: break;
          case  ("abcd"[1]): break;
       }
    I get "error: an array reference cannot appear in a constant-expression"...
    See more | Go to post

    Leave a comment:


  • tanvalley
    started a topic integer constant expression
    in C

    integer constant expression

    why is
    Code:
     ("abcd"[1])
    not an integer constant expression?
    See more | Go to post
No activity results to display
Show More
Working...