by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    For tonight meetings
    AlanU
    @AlanU

    Recomended Reading List

    Programming -- Principles and Practice Using C++ (Second edition)
    https://www.stroustrup.com/programming.html

    The C++ Programming Language, 4th Edition
    https://www.amazon.com/C-Programming-Language-4th/dp/0321563840

    A Tour of C++ (Second edition)
    https://www.stroustrup.com/tour2.html

    C++ Concurrency in Action (Second edition)
    https://www.manning.com/books/c-plus-plus-concurrency-in-action-second-edition?query=C++%20Concurrency%20in%20Action

    Vijayendar Sridharan
    @Veejay_83_twitter
    Hrishikesh
    @hspd

    include<stdio.h>

    include<stdlib.h>

    define MY_CONST 01

    typedef struct tMyType1
    {
    char arr[1000];
    int *ptr1;
    }tMyType1;

    typedef struct tMyType2
    {
    char arr[2000];
    tMyType1 *ptr2;
    }tMyType2;

    typedef struct tMyType3
    {
    char arr[3000];
    tMyType2 *ptr3;
    }tMyType3;

    typedef struct tMyType4
    {
    char arr[4000];
    tMyType3 *ptr4;
    }tMyType4;

    typedef struct tMyType5
    {
    char arr[5000];
    tMyType4 *ptr5;
    }tMyType5;

    tMyType5 *gdata = NULL;

    //This is dummy function, in real case consider it as init routine
    // which need following resource in order, if failed let's retry next time
    int myFunc()
    {
    int x = 0;
    if (gdata)
    return x;
    gdata = (tMyType5 *)calloc( sizeof(tMyType5),1);

    if (!gdata)
        { x = 1; goto label1; }
    
    gdata->ptr5 = NULL ;    
    gdata->ptr5 = (tMyType4 *)calloc( sizeof(tMyType4),1);        
    if (! gdata->ptr5)
        { x = 2 ; goto label2; }
    
    gdata->ptr5->ptr4 = NULL;    
    gdata->ptr5->ptr4 = (tMyType3 *)calloc( sizeof(tMyType3),1);        
    if (! gdata->ptr5->ptr4)
        { x = 3 ; goto label3; }
    
    gdata->ptr5->ptr4->ptr3 = NULL;    
    gdata->ptr5->ptr4->ptr3 = (tMyType2 *)calloc( sizeof(tMyType2),1);    
    if (! gdata->ptr5->ptr4->ptr3)
        { x = 4 ; goto label4; }
    
    gdata->ptr5->ptr4->ptr3->ptr2 = NULL;
    gdata->ptr5->ptr4->ptr3->ptr2 = (tMyType1 *)calloc( sizeof(tMyType1),1);    
    
    if (! gdata->ptr5->ptr4->ptr3->ptr2)
        { x = 5 ; goto label5; }
    
    gdata->ptr5->ptr4->ptr3->ptr2->ptr1 = NULL;
    gdata->ptr5->ptr4->ptr3->ptr2->ptr1 =     (int *)calloc( sizeof(int),1);
    
    if (! gdata->ptr5->ptr4->ptr3->ptr2->ptr1)
        { x = 5 ; goto label6; }
    
    *( gdata->ptr5->ptr4->ptr3->ptr2->ptr1) = MY_CONST;
    return x;    

    label6: free( gdata->ptr5->ptr4->ptr3->ptr2 );
    label5: free( gdata->ptr5->ptr4->ptr3 );
    label4: free( gdata->ptr5->ptr4 );
    label3: free( gdata->ptr5 );
    label2: free( gdata );
    label1:
    return x;
    }

    int main ()
    {
    while ( myFunc() );
    printf ("System booted up !!!");
    }

    Hrishikesh
    @hspd
    Here's a quote from Bjarne Stroustrup, creator of C++, "The fact that 'goto' can do anything is exactly why we don't use it."
    Vitaliy Honcharenko
    @vgoncharenko
    Dejkstra wrote a good topic about it =) He basically was complained about reasoning of the code with 'go to'
    marcaroni
    @officer-tuba
    he said the more a programmer uses goto the worse a programmer they are
    AlanU
    @AlanU
    @vgoncharenko is this what you are talking about https://homepages.cwi.nl/~storm/teaching/reader/Dijkstra68.pdf
    Vitaliy Honcharenko
    @vgoncharenko
    yes
    std::atexit
    Hrishikesh
    @hspd
    @AlanU @grantrostig Can you suggest some reading for QT
    1 reply
    -std=
    Grant Rostig
    @grantrostig
    I got trouble for defending "goto" but even Knuth apparently approved of it: https://www.codeproject.com/Lounge.aspx?msg=5750592#xx5750592xx
    We c++ people could discuss it on that forum, or during a meeting.
    Vijayendar Sridharan
    @Veejay_83_twitter
    AlanU
    @AlanU
    #include <future>
    #include <iostream>
    #include <chrono>
    #include <random>
    
    int main(int /*argc*/, const char ** /*argv[]*/) {
    
    std::random_device rd;
    std::mt19937 mt(rd());
    std::uniform_real_distribution<double> dist(1.0, 10000.0);
    
    unsigned int deviserInt = dist(mt);
    float deviseFloat = dist(mt);
    const unsigned int TIME = 1'000'000'000;
    
    std::chrono::steady_clock::time_point beginInt = std::chrono::steady_clock::now();
        for ( unsigned int index = 0; index < TIME ; ++index) {
              int integer = 60000/deviserInt;
        }
    std::chrono::steady_clock::time_point endInt = std::chrono::steady_clock::now();
    
    std::chrono::steady_clock::time_point beginFloat = std::chrono::steady_clock::now();
        for ( unsigned int index = 0; index < TIME ; ++index) {
             float floatNum = 60000.0f/deviseFloat;
        }
    std::chrono::steady_clock::time_point endFloat = std::chrono::steady_clock::now();
    
    std::cout << "Time difference Int=   "<<std::chrono::duration_cast<std::chrono::microseconds>(endInt - beginInt).count() << "[µs]" << " Size of "<<sizeof (int) <<" Bytes" <<std::endl;
    std::cout << "Time difference Float= "<< std::chrono::duration_cast<std::chrono::microseconds> (endFloat - beginFloat).count() << "[µs]" << " Size of "<<sizeof (float)<< " Bytes"<< std::endl;
    
    return 0;
    }
    int main(int /*argc*/, const char ** /*argv[]*/) {
    
        std::vector<int> list = {1,4,6,4,67,84,43,5,7,4};
        int cArray[100];
        std::reverse(std::begin(list),std::end(list)); //c++ 17
        //  std::reverse(list.begin(),list.end()); //c++ 17 Same as above
        std::reverse(std::begin(cArray),std::end(cArray)); //c++ 17
    
        //C++ 20
        //auto results =  std::views::reverse(list)
        return 0;                                      
    }
    Hrishikesh
    @hspd
    std::vector vec{1, 2, 3, 4, 5, 6};
    auto v = std::views::reverse(vec);
    AlanU
    @AlanU
    thanks
    Hrishikesh
    @hspd

    void my_func(int) { / ... / }

    struct my_class {
    void my_member(int) { / ... / }
    };

    delegate<void(int)> my_delegate;
    my_delegate.connect<&my_func>();
    my_delegate(42);

    my_class instance;
    my_delegate.connect<&my_class::my_member>(&instance);
    my_delegate(42);

    Vitaliy Honcharenko
    @vgoncharenko
    Hrishikesh
    @hspd
    @vgoncharenko thanks
    Vitaliy Honcharenko
    @vgoncharenko
    actually, I would suggest to see his entire set of memory model presentations
    Hrishikesh
    @hspd
    Sure
    Vitaliy Honcharenko
    @vgoncharenko
    at least first 2 really cool =)
    Hrishikesh
    @hspd

    void my_func(int) { / ... / }

    struct my_class {
    void my_member(int) { / ... / }
    };

    delegate<void(int)> my_delegate;
    my_delegate.connect<&my_func>();
    my_delegate(42);

    my_class instance;
    my_delegate.connect<&my_class::my_member>(&instance);
    my_delegate(42);

    Vijayendar Sridharan
    @Veejay_83_twitter
    Vitaliy Honcharenko
    @vgoncharenko
    in case, someone have oreilly subscription, just 2 hours of brief intro into all features of c++20(2a): https://learning.oreilly.com/videos/c-20-2a/9781839216909
    AlanU
    @AlanU
    they also have the course on udemy
    For those who like 'good old' Microsoft visual studio compilers