Sunday, May 11, 2014

simple class

Newsgroup: comp.lang.c++

Subject: simple class

From: nvangogh <nvangogh@...>

Date: Fri, 09 May 2014 14:53:51 +0100



Hi,

I am reading c++ primer.



Exercise 7.4:

Write a class named person that represents the name and address of a

person. Use a string to hold each of these elements. Subsequent

exercises will incrementally add features to this class.



Exercise 7.5:

Provide operations in your person class to return the name and address.

Should these functions be const? Explain your choice.



So I have completed exercise 7.5 in this way:



// a class named person with operations



#include <string>



class Person

{

std::string name() const { return first_name;}

std::string addr() const { return address;}



// data members

std::string first_name;

std::string address;

};



Is this correct?









via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1l7kTAL

View all the progranning help forums at:

http://ift.tt/1dP9txN

Thursday, May 8, 2014

Does C++ Primer offer non-trivial example programs? If not, please suggest a book that does.

Newsgroup: comp.lang.c++

Subject: Does C++ Primer offer non-trivial example programs? If not, please suggest a book that does.

From: Aditya Raj Bhatt <adityarajbhatt@...>

Date: Thu, 8 May 2014 05:09:21 -0700 (PDT)



I am seeing recommendations for C++ Primer everywhere (on the C++-faq lite, the stackoverflow list of C++ books) and other places. Now, I bought it and went through the index, but I was dismayed to find only C++ _features_ listed, and no sign of any non-trivial examples.



I have gone through Object Oriented Programming in _Turbo_ C++ by Robert Lafore. While severely outdated, it taught me many useful applications of the features in C++ (A card game, a horse simulation, fractals, a small adventure game) etc. I was wondering if C++ primer offers examples like this. I find it gets very dull if they just say something like, "you can pass a reference parameter using &. Eg.



void Examplefunction (int &x, int &y) {

x=5; y=6;

}



int main() {

int x,y; Examplefunction(x,y);

return 0;

}



"





Stuff like this is very boring to me, with no possible application. I mean, I am not a very creative person, and unless the application of a concept is shown to me explicitly through some useful example, I have a hard time remembering it. So can someone tell me if C++ Primer offers things like this (please mention what specific example it is). And if not, please recommend a book that is heavy on both explanation and big examples (at least, big from the point of a beginner).



Thank you and sorry for being overly verbose. This is my first post on this group.







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1obopQE

View all the progranning help forums at:

http://ift.tt/1dP9txN

Thursday, May 1, 2014

ostream Problem

Newsgroup: comp.lang.c++

Subject: ostream Problem

From: mrc2323@...

Date: Thu, 1 May 2014 13:46:07 -0700



I am trying to combine std::left and std::setw() as a single

function. The following code ignores the "left" manipulator. What am I

doing wrong? TIA



struct leftsetw // combined functions (left/width)

{

leftsetw(int w) : width(w) {}

int width;

};

ostream &operator<<(ostream &o, const leftsetw &a)

{

o.left, o.width(a.width);

return o;

}



ostringstream oss;

oss.str(""); oss << "Test " << leftsetw(12) << 42;



---

This email is free from viruses and malware because avast! Antivirus protection is active.

http://www.avast.com









via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1rUi3oo

View all the progranning help forums at:

http://ift.tt/1dP9txN

Wednesday, April 30, 2014

Onslaught

Newsgroup: comp.lang.c++

Subject: Re: Onslaught

From: Chris Hinsley <chris.hinsley@...>

Date: Wed, 30 Apr 2014 14:33:39 +0100



On 2013-06-07 17:42:45 +0000, Chris Hinsley said:



Mmm, Has anyone even had a look ? I do have an improved version of the

engine that is mush more c++ if anyone is interested. But this code is

old enough not to drag into the future.



Regards



Chris









via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1nJ4w3h

View all the progranning help forums at:

http://ift.tt/1dP9txN

Tuesday, April 29, 2014

=?ISO-8859-1?Q?=A73=2E5=2F6_in_the_C=2B=2B11_Standard?=

Newsgroup: comp.lang.c++

Subject: =?ISO-8859-1?Q?=A73=2E5=2F6_in_the_C=2B=2B11_Standard?=

From: Ayrosa <jabelloc@...>

Date: Tue, 29 Apr 2014 12:44:18 -0700 (PDT)



§3.5/6



The name of a function declared in block scope and the name of a variable declared by a block scope extern declaration have linkage. If there is a visible declaration of an entity with linkage having the same name and

type, ignoring entities declared outside the innermost enclosing namespace scope, the block scope declaration declares that same entity and receives the linkage of the previous declaration. If there is more than one such matching entity, the program is ill-formed. Otherwise, if no matching entity is found, the block scope entity receives external linkage.[ Example:



static void f();

static int i = 0; // #1

void g() {

extern void f(); // internal linkage

int i; // #2 i has no linkage

{

extern void f(); // internal linkage

extern int i; // #3 external linkage

}

}



There are three objects named i in this program. The object with internal linkage introduced by the declaration in global scope (line #1 ), the object with automatic storage duration and no linkage introduced by the declaration on line #2, and the object with static storage duration and external linkage introduced by the declaration on line #3. --end example ]



Consider the i object in line #3. Why does it have static storage duration and external linkage?







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1m8TcOw

View all the progranning help forums at:

http://ift.tt/1dP9txN

new 2014 women's spiked pointed toe genuine leather red bottom high-heels shoes,designer brand women 12cm pumps wedding shoes

Newsgroup: comp.lang.c++

Subject: new 2014 women's spiked pointed toe genuine leather red bottom high-heels shoes,designer brand women 12cm pumps wedding shoes

From: toptradea@...

Date: Tue, 29 Apr 2014 08:32:57 -0700 (PDT)



new 2014 women's spiked pointed toe genuine leather red bottom high-heels shoes,designer brand women 12cm pumps wedding shoes



http://ift.tt/1mWL5kV



top fashion store 2014(http://ift.tt/1mWL3cV)

Men Sneakers(http://ift.tt/1m80D8v)

Men Flats(http://ift.tt/1mWL14H)

Men Sandals(http://ift.tt/1m80F0i)

Women Sneakers(http://ift.tt/1mWL3d1)

Women Pumps(http://ift.tt/1m80FgA)

Women Sandals(http://ift.tt/1mWL14N)

Women Flats(http://ift.tt/1m80G44)

Women Boots(http://ift.tt/1m80FgG)

Women Clothing(http://ift.tt/1m80G47)

Women Dresses(http://ift.tt/1mWL3JR)

Women Bandage Dress(http://ift.tt/1m80G4g)

Women Bandage Jumpsuit(http://ift.tt/1mWL1lf)

Children Clothing Boys Girls Sets Shoes(http://ift.tt/1m80G4i)

Brazilian virgin hair (http://ift.tt/1mWL3K3)

Malaysian Virgin Hair (http://ift.tt/1mWL1ll)

Peruvian Virgin Hair (http://ift.tt/1mWL1BC)

Indian Virgin Hair (http://ift.tt/1mWL1BI)

Mongolian Virgin Hair (http://ift.tt/1m80Fx7)







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1mWL2Wm

View all the progranning help forums at:

http://ift.tt/1dP9txN

Hot sale new summer 2014 women's causal princess dress,brand designer round neck high waist sleeveless dresses Free shipping S M L Discount Price:US $14.42

Newsgroup: comp.lang.c++

Subject: Hot sale new summer 2014 women's causal princess dress,brand designer round neck high waist sleeveless dresses Free shipping S M L Discount Price:US $14.42

From: toptradea@...

Date: Tue, 29 Apr 2014 08:23:30 -0700 (PDT)



Hot sale new summer 2014 women's causal princess dress,brand designer round neck high waist sleeveless dresses Free shipping SML

S M L Discount Price:US $14.42

http://ift.tt/1mWL4xp



top fashion store 2014(http://ift.tt/1mWL3cV)

Men Sneakers(http://ift.tt/1m80D8v)

Men Flats(http://ift.tt/1mWL14H)

Men Sandals(http://ift.tt/1m80F0i)

Women Sneakers(http://ift.tt/1mWL3d1)

Women Pumps(http://ift.tt/1m80FgA)

Women Sandals(http://ift.tt/1mWL14N)

Women Flats(http://ift.tt/1m80G44)

Women Boots(http://ift.tt/1m80FgG)

Women Clothing(http://ift.tt/1m80G47)

Women Dresses(http://ift.tt/1mWL3JR)

Women Bandage Dress(http://ift.tt/1m80G4g)

Women Bandage Jumpsuit(http://ift.tt/1mWL1lf)

Children Clothing Boys Girls Sets Shoes(http://ift.tt/1m80G4i)

Brazilian virgin hair (http://ift.tt/1mWL3K3)

Malaysian Virgin Hair (http://ift.tt/1mWL1ll)

Peruvian Virgin Hair (http://ift.tt/1mWL1BC)

Indian Virgin Hair (http://ift.tt/1mWL1BI)

Mongolian Virgin Hair (http://ift.tt/1m80Fx7)







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1mWL28M

View all the progranning help forums at:

http://ift.tt/1dP9txN

new 2014 summer children's 100% cotton sets,cute girls clothing baby sleeveless T-shirts+ shorts1 2 3year old Free shipping Discount Price:US $16.07

Newsgroup: comp.lang.c++

Subject: new 2014 summer children's 100% cotton sets,cute girls clothing baby sleeveless T-shirts+ shorts1 2 3year old Free shipping Discount Price:US $16.07

From: toptradea@...

Date: Tue, 29 Apr 2014 08:13:48 -0700 (PDT)



new 2014 summer children's 100% cotton sets,cute girls clothing baby sleeveless T-shirts+ shorts1 2 3year old Free shipping



http://ift.tt/1m80IJo



top fashion store 2014(http://ift.tt/1mWL3cV)

Men Sneakers(http://ift.tt/1m80D8v)

Men Flats(http://ift.tt/1mWL14H)

Men Sandals(http://ift.tt/1m80F0i)

Women Sneakers(http://ift.tt/1mWL3d1)

Women Pumps(http://ift.tt/1m80FgA)

Women Sandals(http://ift.tt/1mWL14N)

Women Flats(http://ift.tt/1m80G44)

Women Boots(http://ift.tt/1m80FgG)

Women Clothing(http://ift.tt/1m80G47)

Women Dresses(http://ift.tt/1mWL3JR)

Women Bandage Dress(http://ift.tt/1m80G4g)

Women Bandage Jumpsuit(http://ift.tt/1mWL1lf)

Children Clothing Boys Girls Sets Shoes(http://ift.tt/1m80G4i)

Brazilian virgin hair (http://ift.tt/1mWL3K3)

Malaysian Virgin Hair (http://ift.tt/1mWL1ll)

Peruvian Virgin Hair (http://ift.tt/1mWL1BC)

Indian Virgin Hair (http://ift.tt/1mWL1BI)

Mongolian Virgin Hair (http://ift.tt/1m80Fx7)







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1m80GRE

View all the progranning help forums at:

http://ift.tt/1dP9txN

Wholesale New 2014 Women Brand Summer Sweet Yellow Milk Adventure Dress,Ladies Sexy Mini Causal Beach Dress Free Shipping S M L

Newsgroup: comp.lang.c++

Subject: Wholesale New 2014 Women Brand Summer Sweet Yellow Milk Adventure Dress,Ladies Sexy Mini Causal Beach Dress Free Shipping S M L

From: toptradea@...

Date: Tue, 29 Apr 2014 08:11:26 -0700 (PDT)



Wholesale New 2014 Women Brand Summer Sweet Yellow Milk Adventure Dress,Ladies Sexy Mini Causal Beach Dress Free Shipping S M L



http://ift.tt/1m80D8t



top fashion store 2014(http://ift.tt/1mWL3cV)

Men Sneakers(http://ift.tt/1m80D8v)

Men Flats(http://ift.tt/1mWL14H)

Men Sandals(http://ift.tt/1m80F0i)

Women Sneakers(http://ift.tt/1mWL3d1)

Women Pumps(http://ift.tt/1m80FgA)

Women Sandals(http://ift.tt/1mWL14N)

Women Flats(http://ift.tt/1m80G44)

Women Boots(http://ift.tt/1m80FgG)

Women Clothing(http://ift.tt/1m80G47)

Women Dresses(http://ift.tt/1mWL3JR)

Women Bandage Dress(http://ift.tt/1m80G4g)

Women Bandage Jumpsuit(http://ift.tt/1mWL1lf)

Children Clothing Boys Girls Sets Shoes(http://ift.tt/1m80G4i)

Brazilian virgin hair (http://ift.tt/1mWL3K3)

Malaysian Virgin Hair (http://ift.tt/1mWL1ll)

Peruvian Virgin Hair (http://ift.tt/1mWL1BC)

Indian Virgin Hair (http://ift.tt/1mWL1BI)

Mongolian Virgin Hair (http://ift.tt/1m80Fx7)







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1mWL1BM

View all the progranning help forums at:

http://ift.tt/1dP9txN

Monday, April 28, 2014

wholesale New 2014 men's blue/grey canvas breathable summer casual sports shoes,designer loafers,men lazy sneakers shoes

Newsgroup: comp.lang.c++

Subject: wholesale New 2014 men's blue/grey canvas breathable summer casual sports shoes,designer loafers,men lazy sneakers shoes

From: aaashoestore1986@...

Date: Mon, 28 Apr 2014 07:32:16 -0700 (PDT)



New 2014 men's blue/grey canvas breathable summer casual sports shoes,designer loafers,men lazy sneakers shoes



http://ift.tt/1hKJ0TO









via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1iy7oxa

View all the progranning help forums at:

http://ift.tt/1dP9txN

Can template arguments have nested template classes?

Newsgroup: comp.lang.c++

Subject: Can template arguments have nested template classes?

From: Alex <alexhagenzanker@...>

Date: Mon, 28 Apr 2014 05:00:07 -0700 (PDT)



Is there something wrong with requiring that a template argument has a nested class template? Why can I not do the following?



template<typename A, typename T> struct B

{

typedef typename A::AA<T> my_type;

};



VS2013 gives a compile error, even if B is not used at all.



What could I do instead?



Thanks, Alex







p.s. what I really want to do is the following:



template<typename A>

struct B

{

template<typename T>

struct BB : A::AA<T>

{};

};







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1iy7owW

View all the progranning help forums at:

http://ift.tt/1dP9txN

LDAP certificate check - how?

Newsgroup: comp.lang.c++

Subject: LDAP certificate check - how?

From: Torsten Mueller <muellerto@...>

Date: Mon, 28 Apr 2014 13:54:50 +0200



I know this topic is special and not many people have to face this. But

I have to.



I connect to an Active Directory server using LDAP (Wldap32.dll,

functions in Winldap.h) to request and modify some data.



The connection (SSL) allows certificate checks, one for the server's and

one for the client's certificate. I would a least implement the check of

the server's certificate. In LDAP there's a callback function which is

indeed called when I open the connection:



BOOLEAN _cdecl VerifyServerCert(PLDAP Connection, PCCERT_CONTEXT* ppServerCert)

{

// ...

return TRUE; // don't check, just accept the server certificate

}



But I have no idea where to begin with this. How should I start to

interpret this PCCERT_CONTEXT struct list? Could anyone give me a short

introduction into this?



Note: I don't want to use any additional library like OpenSSL for that.



T.M.







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1hKJ1Hj

View all the progranning help forums at:

http://ift.tt/1dP9txN

dup2

Newsgroup: comp.lang.c++

Subject: dup2

From: Hongliang Wang <loudking@...>

Date: Tue, 22 Apr 2014 01:35:06 -0700 (PDT)



Hell all,



I was trying to redirect stdout to a file by using dup2. First I followed microsoft example: http://ift.tt/1iy7o06



it just works fine.



Then I tried to implement this in my own class (ABCLog) but stdout is not captured. I cannot figure it out. The only reason I could think of is that main() is in main.cpp while class ABCLog are in separate files (ABCLog.cpp and ABCLog.h). Could anybody confirm this please?



int main(int argc, char *argv[])

{

ABCLog *log = new ABCLog();



puts("in main");

fflush( stdout );



delete log;



return 0;

}



ABCLog::ABCLog(const char *logFileName)

{

old = _dup(1); /* "old" refers to stdout */

if(old == -1) {

perror(ERR_000104_DUP);

exit(1);

}



if( fopen_s( &logFile, logFileName, "a" ) != 0 ) {

fprintf(stderr, ERR_000105_LOG_FILE_OPEN, logFileName);

exit( 1 );

}



if( -1 == _dup2( _fileno( logFile ), 1 ) ) {

perror( ERR_000106_DUP2 );

exit( 1 );

}



puts("in ABCLog");

fflush(stdout);

}



/**

* Destructor

*/

ABCLog::~ABCLog()

{

_dup2( old, 1 );

_flushall();

m_stream.close();

}







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1hKJ0mS

View all the progranning help forums at:

http://ift.tt/1dP9txN

error while using the function size ()

Newsgroup: comp.lang.c++

Subject: error while using the function size ()

From: Milica Milojevic <milicam363@...>

Date: Mon, 28 Apr 2014 04:09:11 -0700 (PDT)



Hi,



I have created a list called measuresQueue (list<pssMeasure *> measuresQueue; ) which is consisted of ten elements. Then I used measuresQueue.size() function. When I did the printf of the previous function it prints me the number four not ten. Can someone help me with this problem.



Here is my code:



In for loop I have entered my elements of the list:



for (filtertime_t=0; filtertime_t<=1.8; filtertime_t=filtertime_t+0.2) {



pssMeasure *mes = measureReceived(filtertime_t,y,mes_vect,mes_cov);

y++;



process_th->critical_section->writeMeasures(mes);



}

Here it is the measureReceived function description:

pssMeasure * measureReceived(double timeStamp,int j,double array[3][10], double array_cov[3]) {





pssMeasure *mes = new pssMeasure();





mes->track_id =7;

mes->timeStamp =timeStamp;



for (int i=0; i<3; i++)

{

mes->z_t[i]=array[i][j];



}





for(int i = 0; i < 3; i++) {



for(int k = 0; k < 3; k++)

mes->cov_z[i][k] = 0.0;



mes->cov_z[i][i] = array_cov[i];





}

return mes;

}

After creating mes I store them using the function writeMeasures:



void CPSSCriticalSection::writeMeasures(pssMeasure* pss_mes) {



measuresQueue.push_back(pss_mes);}



In order to check that my all elements are stored in the measuresQueue list I have used this after the measuresQueue.push_back(pss_mes);



cout << "hello1" << endl

printf("%f %f %f %f \n", pss_mes->timeStamp, pss_mes->z_t[0], pss_mes->z_t[1], pss_mes->z_t[2]);



Everything was fine until I wanted to see the size of my list measuresQueue with the: cout << "measuresQueue. size: " << measuresQueue.size() << '\n';



I always get the number 4 instead of ten. I don't know what is the reason?











Thank you,

M.













via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1pHsde9

View all the progranning help forums at:

http://ift.tt/1dP9txN

Sunday, April 27, 2014

WM_CLOSE in child window procedure problems

Newsgroup: comp.lang.c++

Subject: WM_CLOSE in child window procedure problems

From: ProDev7 <chenou7@...>

Date: Sun, 27 Apr 2014 09:35:08 -0500



hello everybody. I developped an mdi application everything is ok. but in the child window procedure if I handle WM_CLOSE:

if I maximize a child window then close it form its close box icon it'll be destroyed normally but its icon and its close box and minimize and maximize boxes are still there. if I don't handle WM_CLOSE everything is ok.

what's wrong with WM_CLOSE in child window procedure?



LRESULT callback ChildWinProc(HWND hWnd,UINT msg,WPARAM wParam,lParam)

{

//case WM_CLOSE:

// DestroyWindow(hWnd);

break;

default:

return DefMDIChildProc(hWnd,msg,wParam,lParam);

}

if I Uncomment the above lines the problem starts if I maximize the child window and then closing it













via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1h4H2yi

View all the progranning help forums at:

http://ift.tt/1dP9txN

shared_ptr problems

Newsgroup: comp.lang.c++

Subject: shared_ptr problems

From: cpisztest@...

Date: Thu, 24 Apr 2014 14:34:39 -0700 (PDT)



I wasn't around at design time, but I get to fix the problem...story of my life!



I know about boost::weak_ptr and would use that if the problem was limited to

classes A and B, but C has a public accessor that gives away shared_ptrs to As and I don't know what to do there.



I was thinking of trying to guarentee that Bs and Cs are only created by As and seeing if the compiler complained or not (unknown code base). If I can guarentee that Bs and Cs are only created by and used by As, then I can safely use weak_ptrs...I think. I could do that by hiding constructors of Bs and Cs making them private and friending them to A....I think.



Any thoughts/ideas?



The mess where nothing gets destroyed:



-----

#ifndef A_H

#define A_H



#include <boost/shared_ptr.hpp>

#include <boost/enable_shared_from_this.hpp>



#include <list>



class B;

class C;



class A : public boost::enable_shared_from_this<A>

{

public:



typedef boost::shared_ptr<A> SharedPtr;



A();

~A();



void Foo();



private:



std::list<B *> m_collectionOfBs;



void CleanupBs();

};



#endif

-----

#ifndef B_H

#define B_H



#include "A.h"

#include "C.h"



//--------

class B

{

public:



B(A::SharedPtr a);

~B();



private:



C m_c;

};



#endif

-----

#ifndef C_H

#define C_H



#include "A.h"



class C

{

public:



C(A::SharedPtr a);

~C();



A::SharedPtr GetA();



private:



A::SharedPtr m_a;

};



#endif

-----



#include "A.h"

#include "B.h"



A::A()

{

}



A::~A()

{

CleanupBs();

}



void A::Foo()

{

B * newbie = new B(shared_from_this());

m_collectionOfBs.push_back(newbie);

}



void A::CleanupBs()

{

std::list<B *>::iterator it = m_collectionOfBs.begin();



while (!m_collectionOfBs.empty() &&

it != m_collectionOfBs.end())

{

delete (*it);

it = m_collectionOfBs.erase(it);

}

}

-----

#include "B.h"



B::B(A::SharedPtr a)

:

m_c(a)

{

}



B::~B()

{

}

-----

#include "C.h"



C::C(A::SharedPtr a)

:

m_a(a)

{

}



C::~C()

{

}



A::SharedPtr C::GetA()

{

return m_a;

}

-----

#include "A.h"



int main()

{

A::SharedPtr a(new A());

a->Foo();



return 0;

}







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1h3uMht

View all the progranning help forums at:

http://ift.tt/1dP9txN

Monday, March 17, 2014

abstract class with virtual base class and non default constructor

Newsgroup: comp.lang.c++

Subject: abstract class with virtual base class and non default constructor

From: =?ISO-8859-1?Q?Marcel_M=FCller?= <news.5.maazl@...>

Date: Sat, 15 Mar 2014 18:26:54 +0100



Virtual base classes are always constructed by the most derived class.

So why need an abstract class a call to the constructor of it's virtual

base?



#include <stdio.h>



class V

{protected:

V(int i) { printf("V::V(%i)\n", i); }

};



class A : public virtual V

{protected:

A() : V(42) {} // <-- required to keep the compiler happy

virtual void PureFunc() = 0;

};



class D : public A

{public:

D(int i) : V(i) {}

protected:

void PureFunc() {}

};



int main()

{ D d(7);

}





From my understanding the constructor call V(42) could never be

executed, isn't it? A cannot be instantiated and any class inheriting

from A must initialize V::V(int) explicitly.





Marcel







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1nzip4T

View all the progranning help forums at:

http://ift.tt/1dP9txN

Thursday, March 13, 2014

Escape sequence and character set problem

Newsgroup: comp.lang.c++

Subject: Re: Escape sequence and character set problem

From: Victor Bazarov <v.bazarov@...>

Date: Thu, 13 Mar 2014 11:44:16 -0400



On 3/13/2014 11:39 AM, nvangogh wrote:

> What values does this literal represent? What type does it have?

> "Who goes with F\145rgus?\012"

>

> This is from C++ Primer exercise 2.7 (p41 of 5th ed)

>

> I cannot figure this out.

>

> F is a suffix for float that only makes sense to me if numeric value

> came before it. But it comes before an escape sequence. What does \145

> mean? Taken as a whole can you explain how this line is put together and

> how I can interpret it?



Inside a string literal, letter F has no special meaning. It's just a

letter. However, \145 is an escape sequence designating a special

character (most likely) with the value of decimal 145, which is actually

not possible in a basic character set limited to -127..127. So, most

likely it's substituted with char(255-145), some negative value, but

will yield the same thing however. Look up in the extended ASCII table

to see what your computer is likely to output. Or just write a small

program to output that literal. If we designate that character with the

asterisk (like in Scrabble) and the newline (the second escape sequence

is the line feed character) with the tilda, the literal becomes "Who

goes with F*rgus?~"



What it will do when you output it depends on the device, though.



V

--

I do not respond to top-posted replies, please don't ask







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1iGNqBO

View all the progranning help forums at:

http://ift.tt/1dP9txN

Which constructor?

Newsgroup: comp.lang.c++

Subject: Which constructor?

From: ram@...

Date: 13 Mar 2014 12:38:42 GMT



I tried to modify the __gnu_debug string after #include

<debug/string> to get this information, but it did not work,

because I am having problems to print something from inside

of it using ?::std::cerr?.



So, maybe someone here can tell me: What constructor or

method or whatever of the string class is called in the

case of each of the following two object definitions?



#include <string> /* ::std::string */



int main()

{ ::std::string s{ "alpha" };

::std::string t ={ "beta" }; }









via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1cWJ8yn

View all the progranning help forums at:

http://ift.tt/1dP9txN

TALK.ORIGINS CENSORS THE TRUTH

Newsgroup: comp.lang.c++

Subject: Re: TALK.ORIGINS CENSORS THE TRUTH

From: Catpain Merca <catpainmerca@...>

Date: Wed, 12 Mar 2014 22:28:55 +0000



On 12/03/2014 22:07, I THRINAXODON wrote:



I've never seen the talk.origins moderator censor the truth. I have

seen him ban some nym-shifting dipshits. I, on the other hand have

snipped your entire rant. Not really censorship, as your original post

still stands, but completely disregarded without being read by me owing

to the stupidity of your subject header.



Catpain Merca









via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1cWJ9lW

View all the progranning help forums at:

http://ift.tt/1dP9txN

Monday, March 10, 2014

Basic Types

Newsgroup: comp.lang.c++

Subject: Basic Types

From: nvangogh <nvangogh@...>

Date: Mon, 10 Mar 2014 17:42:10 +0000



Is it fair (and technically accurate) to say that the only differences

between int, long, long long and short is the number of bits that is

required to represent the type in the computer? Or is there additional

differences than size?







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1neFJoD

View all the progranning help forums at:

http://ift.tt/1dP9txN

Which one(s) of the following std::vector's member functions has the possibility/authority to reduce a vector's capacity?

Newsgroup: comp.lang.c++

Subject: Which one(s) of the following std::vector's member functions has the possibility/authority to reduce a vector's capacity?

From: goodbyeera@...

Date: Sun, 9 Mar 2014 19:11:23 -0700 (PDT)



Which one(s) of the following std::vector's member functions has the possibility/authority to reduce a vector's capacity?



I have 5 member functions in question:

template <class T, class Allocator = allocator<T> >

class vector {

public:

vector<T,Allocator>& operator=(const vector<T,Allocator>& x);

vector<T,Allocator>& operator=(vector<T,Allocator>&& x);

vector& operator=(initializer_list<T>);

void assign(initializer_list<T>);

void clear() noexcept;

};



Notes:

- For assignments: Unlike vector::swap() which explicitly specifies exchanging both contents and capacity, I can't find reliable answers for the various forms of assignments.

- For std::assign(), there are 2 other overloads:

template <class InputIterator> void assign(InputIterator first, InputIterator last);

void assign(size_type n, const T& u);

And they are both explicitly defined in terms of calls to erase() and insert(), so it's guaranteed with no reduce in capacity. But for the overload taking an initializer_list as the argument, I can't find a reliable answer.

- For std::clear(), in C++03, it's explicitly defined in terms of erase(begin(),end()), so it's guaranteed with no reduce in capacity. I can't find equivalent definition in C++11 anymore.



Relevant excerpts from the standard are highly appreciated.



Thanks,

Goodbyeera







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/NRcatl

View all the progranning help forums at:

http://ift.tt/1dP9txN

Saturday, March 8, 2014

Speech Recognition for Neural diseases Persons

Newsgroup: comp.lang.c++

Subject: Speech Recognition for Neural diseases Persons

From: almostcash@...

Date: Sat, 8 Mar 2014 05:08:36 -0800 (PST)



I am making a speech recognition program in C++ for for neural disease person.



the program should take input from the mic and convert the speech into text.



i have tried the microsoft sapi and other normal speech reconition api, however it just doesnt work in my case.



the persons i am talking about they cant prounounce the words properly. they can only speak few words clearly.



so i need an api or something which could use the limited vocablary option in order to convert speech into text.



thats the only way i think to make this work to be done properly.







suggestion needed







thanks









via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1hVPoe3

View all the progranning help forums at:

http://ift.tt/1dP9txN

Tuesday, March 4, 2014

Brand new C++ container released

Newsgroup: comp.lang.c++

Subject: Brand new C++ container released

From: Mr Flibble <flibbleREMOVE_THIS_AND_THIS@...>

Date: Wed, 05 Mar 2014 00:41:37 +0000



A brand new C++ container called "segmented_array" has been released

which offers fast insert/erase anywhere in a controlled sequence:



http://ift.tt/1f4Vl3V



It performs better than its closest competition (avl_array).



Example timings:



std::vector random erase: 17.1273 seconds

std::deque random erase: 17.6862 seconds

std::list random erase: 24.1854 seconds

mkr::avl_array random erase: 0.1263 seconds

neolib::segmented_array (1) random erase: 0.3113 seconds

neolib::segmented_array (2) random erase: 0.1370 seconds

neolib::segmented_array (3) random erase: 0.1206 seconds

neolib::segmented_array (4) random erase: 0.1198 seconds

std::vector random insert: 73.9902 seconds

std::deque random insert: 25.0955 seconds

std::list random insert: 52.6922 seconds

mkr::avl_array random insert: 0.1513 seconds

neolib::segmented_array (1) random insert: 0.2608 seconds

neolib::segmented_array (2) random insert: 0.1170 seconds

neolib::segmented_array (3) random insert: 0.1158 seconds

neolib::segmented_array (4) random insert: 0.1636 seconds

std::vector random access: 0.0055 seconds

std::deque random access: 0.0095 seconds

std::list random access: 60.9293 seconds

mkr::avl_array random access: 0.0850 seconds

neolib::segmented_array (1) random access: 0.1100 seconds

neolib::segmented_array (2) random access: 0.0470 seconds

neolib::segmented_array (3) random access: 0.0352 seconds

neolib::segmented_array (4) random access: 0.0278 seconds

std::vector sequential access: 0.0019 seconds

std::deque sequential access: 0.0026 seconds

std::list sequential access: 0.0133 seconds

mkr::avl_array sequential access: 0.0138 seconds

neolib::segmented_array (1) sequential access: 0.0180 seconds

neolib::segmented_array (2) sequential access: 0.0032 seconds

neolib::segmented_array (3) sequential access: 0.0028 seconds

neolib::segmented_array (4) sequential access: 0.0027 seconds

std::vector sort: 0.0242 seconds

std::deque sort: 0.0491 seconds

std::list sort: 0.0980 seconds

mkr::avl_array sort: 0.7306 seconds

neolib::segmented_array (1) sort: 0.6190 seconds

neolib::segmented_array (2) sort: 0.0579 seconds

neolib::segmented_array (3) sort: 0.0494 seconds

neolib::segmented_array (4) sort: 0.0452 seconds



/Flibble







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1hICWiq

View all the progranning help forums at:

http://ift.tt/1dP9txN

Thursday, February 27, 2014

calling placement new for elements of a deque

Newsgroup: comp.lang.c++

Subject: calling placement new for elements of a deque

From: hbdevelop1@...

Date: Wed, 26 Feb 2014 21:50:29 -0800 (PST)



Hello

For optimisation reasons, I am re-using not used objects in my deque for new objects.

I am doing that this way :

void Score::Add(const char *str, Coordinates &sp)

{

for(deque<Text>::iterator it=scores.begin();it!=scores.end(); ++it)

{

if(it->notUsed==1)

{

it->Reset(str,sp);

return;

}

}



scores.push_back(Text(str,sp));

}



I thought it would be more convenient to call the placement new on the notUsed object instead of Reset.

How can I do this ?

How can I get the address of the not used object so I can use it in the new placement operator?





Thank you in advance







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1cWtAxS

View all the progranning help forums at:

http://ift.tt/1dP9txN

How to download Microsoft Visuail c++ software

Newsgroup: comp.lang.c++

Subject: How to download Microsoft Visuail c++ software

From: 893756098a@...

Date: Tue, 25 Feb 2014 20:22:02 -0800 (PST)



Recently,our class had studied Microsoft Visuail c++.So I want to practice after school,but I can't install this.I would appreciate it if someone could do me a favour!







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1cWtAxC

View all the progranning help forums at:

http://ift.tt/1dP9txN

Sunday, February 23, 2014

hw to get started

Newsgroup: comp.lang.c++

Subject: hw to get started

From: erson212 <erson212@...>

Date: Sun, 23 Feb 2014 01:20:06 -0800 (PST)



Please can some 1 tell me hw to get started with c++, first tin to du







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/MlsTUe

View all the progranning help forums at:

http://ift.tt/1dP9txN

shared_ptr and unique_ptr related question

Newsgroup: comp.lang.c++

Subject: shared_ptr and unique_ptr related question

From: somenath <somenathpal@...>

Date: Fri, 21 Feb 2014 17:28:19 -0800 (PST)



To get some understanding of shared_ptr and unique_ptr I wrote the following naive implementation of linked list.



#include<memory>

using namespace std;



template <class T>

class List {

private:

class ListItem {

public:

ListItem( T Val );

shared_ptr <ListItem > Next;

T Data;



};



shared_ptr< ListItem >Head;



public:

int CreateNode();

List() {

Head.reset();

}

void PushBack(T Val);

void Dump();

};





template<class T>

List<T>::ListItem::ListItem( T Val):Data(Val) {

Next.reset();





}

template<class T>

void List<T>::PushBack( T val)

{

unique_ptr<ListItem > NewItem (new ListItem(val));

if (!Head ) {

Head = move(NewItem);

}

else {

shared_ptr<ListItem> Curr(Head);

shared_ptr<ListItem> Prev(Head);

while( (Curr) ) {

Prev = Curr;

Curr = Curr->Next;

}

Prev->Next = move(NewItem);

}

}



template<class T>

void List<T>::Dump() {

shared_ptr<ListItem > Curr(Head);

while ( Curr) {

cout<<"Val = "<<Curr->Data<<endl;;

Curr = Curr->Next;

}

}



But I am not very clear of the correct uses of shared_ptr and auto_ptr yet. Could you please comment on the uses of smart pointers in the context of my linked list code. According to my understanding where I do not need to assign smart pointers to other one I use unique_ptr . Is this understanding correct?



Also I am not able to get convinced the benefit of shared_ptr and unique_ptr in the context of my code. I could have used even raw pointers to implement the same without losing much benefit . Is it not the case here?



I can use the above code as



int main(int argc,char *argv[] )

{

unique_ptr< List <int> > ilst (new List<int>());



ilst->PushBack(5);

ilst->PushBack(15);

ilst->PushBack(25);

ilst->Dump();



return 0;

}



Is the benefit of using smart pointers is, ilst need to be freed manually?



Please point me to some real code where smart pointers has been heavily used.



--

Somenath







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1pdpjLy

View all the progranning help forums at:

http://ift.tt/1dP9txN

Friday, February 21, 2014

implicit passing by reference

Newsgroup: comp.lang.c++

Subject: implicit passing by reference

From: jerry.jeremiah@...

Date: Thu, 20 Feb 2014 20:45:27 -0800 (PST)



In this topic



http://ift.tt/1fobfKU



The person that answers it says:



You have to remember that objects are sent to functions 'by reference'.



But the object being passed contains only one int member and the function the object is being passed to clearly takes it's parameter by value and stores it in a member value.



Do objects really always pass by reference regardless of what the parameter list says? And, if so, why would it do that? I would usderstand if the function took its parameter explicitly by reference...



Thanks for clearing up mu confusion.



Jerry







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1dcvLKj

View all the progranning help forums at:

http://ift.tt/1dP9txN

Thursday, February 20, 2014

Working with Large Values (double)

Newsgroup: comp.lang.c++

Subject: Working with Large Values (double)

From: mrc2323@...

Date: Thu, 20 Feb 2014 17:25:50 -0700



How can I express a large value as a double? (e.g. 1000000.3)

Whereas this compiles and executes, when I try to convert it to a

string value it converts as a scientific string (e.g. "1e+006", not

"1000000.3"). I want to process all the characters of the value of the

data as a std::string.

Or is there a way to convert the double to assure it's not expressed

in scientific notation? TIA



---

This email is free from viruses and malware because avast! Antivirus protection is active.

http://www.avast.com









via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1gOIwiN

View all the progranning help forums at:

http://ift.tt/1dP9txN

OT: Problem building libc++

Newsgroup: comp.lang.c++

Subject: OT: Problem building libc++

From: woodbrian77@...

Date: Thu, 20 Feb 2014 15:00:24 -0800 (PST)





I was following these instructions



http://ift.tt/UxFMKX



but have a problem when I get to building libc++.



Linking CXX shared library libc++.so

/usr/bin/ld: cannot find -lsupc++





I tried:



find / -type f -name "*supc++*" -print



but it didn't find any files that matched that.



I searched on https://duckduckgo.com and bing for

some ideas, but haven't found the answer.



What do you suggest? Thanks in advance.



Brian

Ebenezer Enterprises - In G-d we trust.

http://webEbenezer.net







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1hzSmrQ

View all the progranning help forums at:

http://ift.tt/1dP9txN

Nested Boost::unordered_map with std::pair insertion help ..

Newsgroup: comp.lang.c++

Subject: Nested Boost::unordered_map with std::pair insertion help ..

From: Rahul Mathur <srivmuk@...>

Date: Thu, 20 Feb 2014 04:32:58 -0800 (PST)



All,



I have having Boost boost::unordered_map nested map calling boost::unordered_map which calls std::map finally.



The LHS (towards RHS) side key for first boost::unordered_map is 'int' type followed by next key being char buffer value of size 10, and key for std::map being again a char buffer value of size 10. So the boost::unordered_map has nested map internally.

I have to insert the char buffer of size 10 (value being either 'ORANGE' or ORD123 as test case) into nested std::pair as defined below. After inserting, I have to search or find the value from char buffer of size 10.



The code as compiled on Linux is -



----

#include <cstdio>

#include <cstdlib>

#include <iostream>

#include <boost/unordered_map.hpp>

#include <map>

#include <algorithm>

#include <string>



using namespace std;



#if 0

#pragma pack(push, 2)

struct BookKeeping {

int ABCD;

char Apple_ID [10];

char Apple_NAME[10];

int Price;

int Number;

};

#pragma pack(pop)

#endif



class Name { // buffer of size 10

char str[10];

public:

Name() {

strcpy(str, "");

}

Name(char *s) {

strcpy(str, s);

}

char *get() {

return str;

}

};



bool operator<(Name a, Name b)

{

return strcmp(a.get(), b.get()) < 0;

}



#pragma pack(push, 2)

struct BookKeeping {

int ABCD;

Name Apple_ID;

Name Apple_NAME;

int Price;

int Number;

};

#pragma pack(pop)



BookKeeping *_bkkping;



typedef boost::unordered_map< int, boost::unordered_map< Name, std::map< Name, int > > > _uordmap; // nested boost::unordered_map



class BkKping {

private:

_uordmap * uordmap;



typedef boost::unordered_map< int, boost::unordered_map< Name, std::map< Name, int > > >::iterator _itr_1;

typedef boost::unordered_map< Name, std::map< Name, int > >::iterator _itr_2;

typedef std::map< Name, int >::iterator _itr_3;



public:

BkKping () {

uordmap = new _uordmap ();

}

void Apple ( int abcd, const char * Apple_ID_, const char * Color_, int Price_ );

~BkKping () {

delete uordmap;

}



};



void BkKping::Apple ( int abcd, const char * Apple_ID_, const char * Color_, int Price_ ) {



uordmap->insert( std::pair< int, std::pair< Name, std::pair< Name, BookKeeping &> > > ( _bkkping->ABCD , _bkkping->Apple_ID, _bkkping->Apple_NAME, *_bkkping) ); // nested std::pair<> insertion

}



int main () {



int abcd;

const char * Apple_ID_;

const char * Color_;

int Price_;



BkKping book;

book.Apple( abcd, Apple_ID_, Color_, Price_);



}

-----



The error message is -



---

hello.cpp: In member function âvoid BkKping::Apple(int, const char*, const char*, int)â:

hello.cpp:76: error: no matching function for call to âstd::pair<int, std::pair<Name, std::pair<Name, BookKeeping&> > >::pair(int&, Name&, Name&, BookKeeping&)â

/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_pair.h:83: note: candidates are: std::pair<_T1, _T2>::pair(const _T1&, const _T2&) [with _T1 = int, _T2 = std::pair<Name, std::pair<Name, BookKeeping&> >]

/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_pair.h:79: note: std::pair<_T1, _T2>::pair() [with _T1 = int, _T2 = std::pair<Name, std::pair<Name, BookKeeping&> >]

/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_pair.h:68: note: std::pair<int, std::pair<Name, std::pair<Name, BookKeeping&> > >::pair(const std::pair<int, std::pair<Name, std::pair<Name, BookKeeping&> > >&)

--



I have created a class buffer to read size 10.



Please help.



P.S: No issue with Boost compilation, simply looking for proper semantic call for nested std::pair<>.







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1hzSmbg

View all the progranning help forums at:

http://ift.tt/1dP9txN

Wednesday, February 19, 2014

Iterator pair as a function argument?

Newsgroup: comp.lang.c++

Subject: Iterator pair as a function argument?

From: nvangogh <nvangogh@...>

Date: Wed, 19 Feb 2014 20:22:47 +0000



Suppose I have a vector<int> values. Now the pair values.begin() and

values.end() will cover the range of the vector.



I am writing a simple function that takes the pair of iterators as

arguments along with an int value. The function then returns a bool to

indicate if the int value is found in the vector.



The first problem I have is to question if it is possible to pass

iterators as distinct arguments to a function? I would have thought that

the only way to accomplish this would be to pass the vector as a

reference, from there the function can use the iterators to do it's work.



I was thinking the correct definition would be



bool find_value (vector<int>&, int);



Or is there a way to pass an iterator pair as function arguments which I

have missed?







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1jJceFN

View all the progranning help forums at:

http://ift.tt/1dP9txN

could an braced-init-list be a first-class expression?

Newsgroup: comp.lang.c++

Subject: could an braced-init-list be a first-class expression?

From: pietro.cerutti@...

Date: Wed, 19 Feb 2014 10:47:33 -0800 (PST)



I'm wondering what would prevent an initialization list from being a first-class expression of type std::initializer_list.



I understand that the current standar allows braced-init-lists to appear only when assigning to a scalar of type T or to an object of a class taking an std::initializer_list in the assignment operator.



Having



void f (std::vector<double> v);



It is currently possible to do this:



auto a {1, 2, 3}:

g (a);



but not to do this:



g ({1, 2, 3});



As I see it, all information the compiler needs is there. Is there any specific reason why this isn't possible?



Thanks,







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/MC6McR

View all the progranning help forums at:

http://ift.tt/1dP9txN

IO problem

Newsgroup: comp.lang.c++

Subject: IO problem

From: nvangogh <nvangogh@...>

Date: Wed, 19 Feb 2014 14:29:18 +0000



I have come to a question in C++ Primer (p 314 , exercise 8.1) that is

not clear to me.

"Write a function that takes and returns an istream&. The function

should read the stream until it hits end-of-file. The function should

print what it reads to the standard output. Reset the stream so that it

is valid before returning the stream."



Breaking this down, the function has to do three things:



1. Read a stream until it hits end-of-file

So the >> operator reads input from an istream object - cin.

This stream's end of file can be interrogated by

cin.eof(). This returns true if the end of file bit is set which can be

tested with a bool variable

bool on = false;

on = cin.eof();

if(on == true)

// end of file is reached, else

if(on ==false)

// keep reading cin



I don't believe that this is completely correct so can someone show me

how this code should be presented?



2. Print what is read to the standard output

I can only imagine this to be cout << ? But am lost from here



3. Reset the stream so it is valid before returning the stream

This section of the problem again defeats me.



Can anyone help with this function?









via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/MC6KSh

View all the progranning help forums at:

http://ift.tt/1dP9txN

pointer to a vector

Newsgroup: comp.lang.c++

Subject: pointer to a vector

From: "A" <a@...>

Date: Wed, 12 Feb 2014 20:46:12 +0100



There are 2 vectors each one having a structure



struct MyStruct

{

int a;

std::string b;

}



std::vector<MyStruct> v1;

std::vector<MyStruct> v2;



Now I want a pointer to which one I will use... v1 or v2



std::vector<MyStruct> *v = (condition)? &v1 : &v2;



Finally I access it using:



for (unsigned i = 0; i < v->size(); i++)

{

v->operator[](i).a = i + 1;

}



My lack of understanding here is:



a) does the above *v needs to be deleted? Isn't it just a pointer variable?

Or it works differently when it points to a vector? Just to be clear, I

don't actually need to delete v1 or v2. I just need to cleanup *v if

required.



b) what's the heap or stack or difference or advantage of them in relation

to the above?











via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/MC6KBR

View all the progranning help forums at:

http://ift.tt/1dP9txN

about gets

Newsgroup: comp.lang.c++

Subject: about gets

From: mary8shtr@...

Date: Tue, 11 Feb 2014 09:22:12 -0800 (PST)



hi.I am writing a program.while i define some variable but program say this variable undefined.







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/MC6KBH

View all the progranning help forums at:

http://ift.tt/1dP9txN

Tuesday, February 18, 2014

Flummoxed - Please Help!

Newsgroup: comp.lang.c++

Subject: Flummoxed - Please Help!

From: mrc2323@...

Date: Tue, 18 Feb 2014 12:40:26 -0700



I have the following (rather simple, I think) code which compiles but

executes in a bizarre way: the code in the subprogram is skipped when

called. 8<{{

Here's the code and the call to it I use:



string spellNumber(double value)

{

bool showThousands = false;

bool allZeros = true;

int ii, dPos, nn;

char wc;

string digits, temp;

ostringstream ossw;

static string builder;

ossw.str("");

ossw << value;

digits = ossw.str();

dPos = digits.find('.');

if(dPos != string::npos) digits.erase(dPos);

nn = digits.length();

wc = digits.back();

for(ii = digits.length()-1; ii >= 0; ii--)

{

int ndigit = (int)(digits[ii]-'0');

int column = (digits.length()-(ii+1));

} // for

// more code to be added here

return builder;

}

...

spellNumber(123.45); // call the function



I have, of course the normal stdafx.h header and "use namespace

std;", and this is code from a small test program I use to debug new

functions and such. Many other programs and many thousands of lines of

code work fine, but this code is weird...and I can't see what's wrong

with it!

Please advise... TIA



---

This email is free from viruses and malware because avast! Antivirus protection is active.

http://www.avast.com









via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/O7tKtA

View all the progranning help forums at:

http://ift.tt/1dP9txN

SMITHSONIAN SHUT DOWN FOR GOOD -- THE THRINAXODON TIMES REPORTS, YOU CALL OUT BULLSHIT

Newsgroup: comp.lang.c++

Subject: SMITHSONIAN SHUT DOWN FOR GOOD -- THE THRINAXODON TIMES REPORTS, YOU CALL OUT BULLSHIT

From: Apidium23 <apidium23@...>

Date: Tue, 18 Feb 2014 14:05:26 -0500



==============

>BREAKING NEWS

==============

>

SMITHSONIAN FINALLY SHUT DOWN AFTER YEARS OF CENSORSHIP, SCAMS AND CON

ARTISTRY.

>

THRINAXODON BLEW DOWN THE BUILDINGS, LIT IT ON FIRE AND HAD THE ASSHOLES

ARRESTED.

>

R. DAWKINS WAS THROWN IN THE DOGHOUSE, ONLY TO GET KILLED BY ANGRY

FELONS WHO WANTED PAYBACK FOR FRAMING THEM.

>

THRINAXODON DANCED ON DAWKINS' GRAVE, AND BURNED A FEW SMITHSONIAN

MAGAZINES.

>

=================================

EVIDENCE THAT HUMANS LIVED IN THE DEVONIAN:



http://ift.tt/O7tKcQ



http://ift.tt/1cXKQzc



====================================



http://ift.tt/O7tKcU



===================================



THRINAXODON ONLY HAD THIS TO SAY:



"I..I...I...Can't believe it. This completely disproved Darwinian

orthodoxy."



===================================



THE BASTARDS AT THE SMITHSONIAN, AND THE LEAKEY FOUNDATION ARE ERODING

WITH FEAR.



===========================

THESE ASSHOLES ARE GOING TO DIE:

THOMAS AQUINAS;

ALDOUS HUXLEY;

BOB CASANVOVA;

SkyEyes;

DAVID IAIN GRIEG;

MARK ISAAK;

JOHN HARSHAM;

RICHARD NORMAN;

DR. DOOLITTLE;

CHARLES DARWIN;

MARK HORTON;

ERIK SIMPSON;

HYPATIAB7;

PAUL J. GANS;

JILLERY;

WIKI TRIK;

THRINAXODON;

PETER NYIKOS;

RON OKIMOTO;

JOHN S. WILKINS

===========================



THRINAXODON WAS SCOURING ANOTHER DEVONIAN FOSSIL BED, AND FOUND A

HUMAN SKULL, AND A HUMAN FEMUR. HE ANALYSED THE FINDS, AND SAW THAT

THEY WERE NOT NORMAL ROCKS. THESE WERE FOSSILIZED BONES. THEY EVEN HAD

TOOTH MARKS ON THEM. SO, THRINAXODON BROUGHT THEM TO THE LEAKEY

FOUNDATION, THEY UTTERLY DISMISSED IT, AND SAID, "We want to keep

people thinking that humans evolved 2 Ma." THRINAXODON BROUGHT HIS

SWORD, AND SAID, "SCIENCE CORRECTS ITSELF." RICHARD LEAKEY SAID, "That

is a myth, for people to believe in science." THRINAXODON PLANS TO

BRING DOOM TO SCIENCE, ITSELF.



============================



THRINAXODON IS NOW ON TWITTER.



======================================

>

THRINAXODON WAS AWARDED

US$100,000,000,000,000,000,000,000,000,000,000,000 ,000,000,000,000,000,000

DOLLARS FOR HIS BRAVE EFFORTS IN SHUTTING DOWN THE EVOLUTIONARY SCAMS.

--

Apidium23:



http://ift.tt/1cXKPLR









via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/O7tKcW

View all the progranning help forums at:

http://ift.tt/1dP9txN

Saturday, February 15, 2014

Can't think of a good subject

Newsgroup: comp.lang.c++

Subject: Can't think of a good subject

From: woodbrian77@...

Date: Wed, 12 Feb 2014 19:45:10 -0800 (PST)





I'm not sure why the behavior of the following

two functions differs here. The only difference

in these functions is in the body of the loop.



template <class R>

void Receive (::cmw::ReceiveBuffer<R>& buf

,empty_container<cmw::File>& az1)

{

int32_t count[1];

count[0]=buf.template Give<uint32_t>();

for(;count[0]>0;--count[0]){

cmw::File inst(buf); // named

}

}





template <class R>

void Receive (::cmw::ReceiveBuffer<R>& buf

,empty_container<cmw::File>& az1)

{

int32_t count[1];

count[0]=buf.template Give<uint32_t>();

for(;count[0]>0;--count[0]){

cmw::File (buf);

}

}





The first (named) version works the way I want

it to, and the second version, built with either

gcc or clang doesn't. Both compilers are

producing smaller text segments for the second

version. And the results for that version

(both compilers) are like nothing is being done

in the loop.



Can someone explain this? In another file I

have some code similar to the second version

and it works fine:



while(fgets(lineBuf,300,Fl.FlHndl)){

token=strtok(lineBuf," ");

if(strcmp("Header",token)) break;

cmw::File (strtok(nullptr,"\n ")).Marshal(buf);

}



I've simplified that loop a little, but don't

think I've removed anything important. There

are different constructors being used in these

two cases.



http://ift.tt/1kJmjpJ



Thanks.



Brian

Ebenezer Enterprises - In G-d we trust.

http://webEbenezer.net







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1gDONNy

View all the progranning help forums at:

http://ift.tt/1dP9txN

Friday, February 14, 2014

a totally self balanced tree for unsigned integers...

Newsgroup: comp.lang.c++

Subject: a totally self balanced tree for unsigned integers...

From: "Chris M. Thomasson" <no@...>

Date: Fri, 14 Feb 2014 13:44:40 -0800



I do not even want to go into why James tried to post this as his own!



:^/ GRRRR!!!!! #$%#$% FUC32432KL#$@...





Anyway, He made a fatal mistake! My name is in my cryptic MACROS!!!!



Take a look:



http://ift.tt/1eYaCcl





HAW HAW!!!!!





:^)





Anyway, I need to use it now for a database.







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1eYaEB1

View all the progranning help forums at:

http://ift.tt/1dP9txN

Sunday, February 9, 2014

Return by reference

Newsgroup: comp.lang.c++

Subject: Return by reference

From: Giuliano Bertoletti <gbe32241@...>

Date: Sun, 09 Feb 2014 12:50:38 +0100





Hello,



I've a classes like this:



class SubObject { ... };



class Object {

public:

SubObject sub;

};



class MyClass {

public:

Object obj;



public:

SubObject &GetSubObject() { return obj.sub; } // shortcut

};



which is the difference of calling?



==================

MyClass c;



SubObject &sub = c.GetSubObject();

SubObject sub = c.GetSubObject();

==================



It compiles both ways.



In practice I've an higher number of nested classes, so GetSubObject()

is actually a shortcut which digs deep into MyClass and retrieves the

item I need.



Giulio.























via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1fWFLLL

View all the progranning help forums at:

http://ift.tt/1dP9txN

Thursday, February 6, 2014

show all subset of a set

Newsgroup: comp.lang.c++

Subject: show all subset of a set

From: mary8shtr@...

Date: Thu, 6 Feb 2014 08:13:54 -0800 (PST)



A program is a set of all subsets of this part of the show. Users can enter a number., For example, if n = 2 the output looks like this:

{}

{1}

{2}

{1,2}

or for n=3 we have:

{}

{1}

{2}

{3}

{1,2}

{1,3}

{2,3}

{1,2,3}

meantime this program should be solved with tow way.

recursive function and Non-recursive.Can also be used in solving the problem of bitwise operations.



my algorithm that is for per subset exists one number. these numbers are form 0 until (2^n)-1.allow me explain it with a example.

n=3

{ } 000 0

{1} 100 4

{2} 010 2

{3} 001 1

{1,2} 110 6

{1,3} 101 5

{2,3} 011 3

{1,2,3} 111 7

The third column show some number(fn) that i use in code.now we know per number of subset has to state(sn).0 or 1. this means it exists or not exists.now i should match fn and sn.and suggested way is use of bitwise operators.(operator &).and now i don't know what do and thing with else thing.

#include <iostream>

using namespace std;

#include <conio.h>

#include <string.h>

int pow(int a,int b)

{

int p=1;

for(int i=0;i<b;i++)

p=p*a;

return p;

}

struct ar

{

int binary;

int content;

};

int main()



{

int testcase=0;

int n;

ar *a;

a=new ar [2000];

cin>>testcase;

int i=0;

while(i<testcase)

{

cin>>n;

for(int j=0,k=1;j<n;j++,k++)

{

a[j].content=k;

a[j].binary=2;

}





for(int p=0;p<pow(2,n)-1;p++)

{

cout<<'{';

for(int m=0;m<n;m++)

{



int b;

b=a[m].binary&p;

if(b==1)

cout<<a[i].content<<' ';



}

cout<<'}';

}



cout<<endl;

i++;

}

return 0;

}







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/LVdQRq

View all the progranning help forums at:

http://ift.tt/1dP9txN

Wednesday, February 5, 2014

question regarding the shared_ptr use_count

Newsgroup: comp.lang.c++

Subject: question regarding the shared_ptr use_count

From: somenath <somenathpal@...>

Date: Sun, 2 Feb 2014 17:12:57 -0800 (PST)



I am not able to understand the behavior of the following program



#include <iostream>

#include<memory>

#include<string>

using namespace std;



int main() {

auto p1 = make_shared<string> (10,'S');

cout<<"p1 use_count = "<<p1.use_count()<<endl;

shared_ptr<string> p2(new string()) ;

p1 = p2;

cout<<"p2 use_count = "<<p2.use_count()<<endl;

cout<<"second p1 use_count = "<<p1.use_count()<<endl;

return 0;

}

Output

++++++++++++++++

p1 use_count = 1

p2 use_count = 2

second p1 use_count = 2



I can understand the first two print. At beginning p1 points to one string so the reference count is 1.

When the statement p1=p2; executes p2's reference count gets incremented to 2 but at the same time I was expecting that p1's reference count to be decremented by 1 as p1 would be pointing to p2 now.

Please let me know where my understanding is going wrong?







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1keZz0q

View all the progranning help forums at:

http://ift.tt/1dP9txN

Saturday, February 1, 2014

Address one past the end of array - is this syntax a valid C++?

Newsgroup: comp.lang.c++

Subject: Address one past the end of array - is this syntax a valid C++?

From: Peter <pilarp@...>

Date: Sat, 1 Feb 2014 09:23:39 -0800 (PST)



Assume we have an array:



int arr[5];



It's legal to refer to address arr + 5, but, of course, illegal to refer to element arr[5] as it's not part of the array. However, arr + n is equivalent to &arr[n]. My question is: does this equivalence also hold for an edge case of

n = 5 (or, generally, n equal to number of elements of array)?



While there's nothing wrong with arr + 5, &arr[5] looks highly suspicious: it looks like in the first step arr[5] is evaluated (which introduces an undefined behaviour) which would mean the expression as a whole is undefined. Does the equivalence still hold in this special case?







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1i4Tpfr

View all the progranning help forums at:

http://ift.tt/1dP9txN

Thursday, January 30, 2014

i really need help

Newsgroup: comp.lang.c++

Subject: i really need help

From: mary8shtr@...

Date: Thu, 30 Jan 2014 07:34:04 -0800 (PST)



Hi.I joined recently to this group .I want write a program in c++ language.one program in c++ that receive two char array from user and print all of state built by this tow arryas.for example users enter "abc" and "mn".program should show abcmn , abmnc , amnbc , mnabc ,mabcn ,manbc, mabnc , ambnc ,ambcn ,abmcn as output.pleas answer me.I very thought on this solution.but I couldn't solve it.and i need it early.I thanks very much if anyone answer me faster.







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1cB0tAa

View all the progranning help forums at:

http://ift.tt/1dP9txN

Tuesday, January 28, 2014

How does the name lookup work in this case?

Newsgroup: comp.lang.c++

Subject: How does the name lookup work in this case?

From: Peter <pilarp@...>

Date: Tue, 28 Jan 2014 12:47:31 -0800 (PST)



Consider this definition (namespace and class share the same name):



namespace Foo

{

int x;



class Foo

{

public:

static int x;

};



int Foo::x;

}



I wondered what Foo::x would refer to with "using" directive used for namespace Foo: a global variable x in namespace Foo or static member of class Foo? Basically, I assumed the following code would not compile:



int main()

{

using namespace Foo;

Foo::x;

return 0;

}



My reasoning went like this:



- Foo::x is a global variable x from namespace Foo

- Foo::Foo::x is a static member of class Foo from namespace Foo, but since

"using" directive is applied, the namespace name can be omitted, thus Foo::x is also a static member of class Foo

- conclusion: call to Foo::x in main() is ambiguous - it refers to two different entities



However, the compiler I tested it with (one of g++ recent versions) had no trouble disambiguating this: experiments showed Foo::x in main() is interpreted as global variable x in namespace Foo. Moreover, if I remove the definition of global x from namespace Foo, then the compiler emits the following error:



main.cpp: In function 'int main()':

main.cpp:16:4: error: 'x' is not a member of 'Foo'

Foo::x;



so it doesn't find the static member of class Foo. In order for the compiler to find it I have to qualify it fully as Foo::Foo::x despite the "using namespace Foo;" line. Why? How does the lookup work here?







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1floQ5s

View all the progranning help forums at:

http://ift.tt/1dP9txN

Boost

Newsgroup: comp.lang.c++

Subject: Boost

From: Nick Baumbach <nich@...>

Date: Fri, 17 Jan 2014 15:11:24 +0000 (UTC)



Does anybody use Boost code, what is it.



I mean, it has to make things easier, but it does not looks like, since it

takes hours to compile.







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1b6a8dS

View all the progranning help forums at:

http://ift.tt/1dP9txN

Monday, January 27, 2014

Moving from C++03 to C++11

Newsgroup: comp.lang.c++

Subject: Moving from C++03 to C++11

From: retro54321@...

Date: Sun, 26 Jan 2014 16:06:20 -0800 (PST)





Could someone please suggest a good book (or any kind of resource) for someone who's very familiar with C++03 and who wants to get up to speed with C++11.



(I was considering getting the 4th addition of Bjarne's book, but rather than read about the entire language from start to finish, I just want to focus on the new stuff brought in with C++11).



Rhino







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1f4Mna3

View all the progranning help forums at:

http://ift.tt/1dP9txN

What is the disadvantage with C++ in Embedded systems?

Newsgroup: comp.lang.c++

Subject: Re: What is the disadvantage with C++ in Embedded systems?

From: deepadivakaruni@...

Date: Sat, 25 Jan 2014 08:48:00 -0800 (PST)



i think so c++ is more complicated when compared to c.And also the many keywords are used to perform only one application.







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1glczRs

View all the progranning help forums at:

http://ift.tt/1dP9txN

goto label inside of if statement

Newsgroup: comp.lang.c++

Subject: goto label inside of if statement

From: W Karas <wkaras@...>

Date: Thu, 23 Jan 2014 11:32:13 -0800 (PST)



I was surprised to find that this code:



struct A { A(); ~A(); };



void bar();



void foo(bool f)

{

if (0)

{

LAB: ;

}

else

{

A a;



if (f) goto LAB;



bar();

}

}



will compile without warnings using GCC 4.7.3, even with -Wall and -Wextra .



The point, in case you were wondering, would be a macro-based "named block" pseudo-construct, where the block could be exited from any depth of block nesting, for example:



#define BLOCK(NAME) if (0) { NAME: ; } else

#define EXITBLOCK(NAME) goto NAME;



struct A { A(); ~A(); };



void bar();



void foo(bool f)

{

BLOCK(XYZ)

{

A a;



if (f) EXITBLOCK(XYZ)



bar();

}

}







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1glcAEV

View all the progranning help forums at:

http://ift.tt/1dP9txN

Saturday, January 18, 2014

memory manager to prevent memory leaks

Newsgroup: comp.lang.c++

Subject: memory manager to prevent memory leaks

From: hbdevelop1@...

Date: Fri, 17 Jan 2014 14:49:25 -0800 (PST)



Hello,



I have written a memory tracker to prevent memory leaks in my programs.

The memory tracker meets the following requirements:

r1-Allocate memory using the system's new/new[].

r2-Deallocate memory using the system's delete/delete[].

r3-Log the file name and line where an allocation happens.

r4-When a memory is fred, remove the memory allocation from the log.

r5-At application exit, display the log.



Please find the code at the end of the email.

I have the following questions :



1-

g++ issues the following warning in my operator delete/delete[]: memtracker4.cpp:24:9: warning: deleting ?void*? is undefined [enabled by default]

delete p;

^

Do you have any idea how to correct the code so I don't get the warning ?



2-

To remove tracks of memory added in my operator new/new[], I am using template functions deleteArray and deleteObj.

But I remember in one company I worked in, they were using new(__FILE__,__LINE__) or new[](__FILE__,__LINE__) for allocations and plain delete/delete[] for deallocation.

And I wonder now, how they were removing memory tracks added by their operator new/new[] since they were using plain delete or delete[] for deallocation.

Could anybody please tell me if this is possible ? or were they not removing tracks ?



3-

Please tell me anything else to improve this code.



/////// code ////////



#include <stdio.h>

#include <new>



void AddToLog(long ptr, size_t size,const char * filename, int line)

{

printf("allocation : 0x%08X,%d,%s,%d\n",ptr, size,filename, line);

}



void RemoveFromLog(long ptr)

{

printf("deallocation : 0x%08X\n",ptr);

}



void * operator new(size_t size, const char *filename, int line)

{

void *ptr = ::operator new(size);

AddToLog((long)ptr, size, filename, line);

return(ptr);

};



void * operator new[](size_t size, const char *filename, int line)

{

void *ptr = ::operator new[](size);

AddToLog((long)ptr, size, filename, line);

return(ptr);

};



void operator delete(void *p, const char *filename, int line)

{

RemoveFromLog((long)p);

delete p; //g++ outputs warning: deleting ?void*? is undefined [enabled by default]

};



void operator delete[](void *p, const char *filename, int line)

{

RemoveFromLog((long)p);

delete [] p; //g++ outputs warning: deleting ?void*? is undefined [enabled by default]

};





template<class T> void deleteObj(T *p)

{

RemoveFromLog((long)p);

delete p;

};



template<class T> void deleteArray(T *p)

{

RemoveFromLog((long)p - sizeof(unsigned int));

delete [] p;

};





struct O11

{

int x;

public:

~O11 (){}

};



#define new new(__FILE__,__LINE__)



int main()

{

char *c=new char;

deleteObj<char>(c);



O11 *o=new O11;

deleteObj<O11>(o);



O11 *o1=new O11[10];

deleteArray<O11>(o1);



char *c3=new char[3];

deleteObj<char>(c3);

/*Note that I am treating c3 as a simple object not as array

(which caused my question at http://ift.tt/1mo3EyX)

*/



return 0;

}







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1f1zigo

View all the progranning help forums at:

http://ift.tt/1dP9txN

Tuesday, January 14, 2014

Decoding GIF file in C? [Source code here]

Newsgroup: comp.lang.c++

Subject: Re: Decoding GIF file in C? [Source code here]

From: kirannd1989@...

Date: Wed, 8 Jan 2014 19:23:59 -0800 (PST)



Hi..

i tried compiling this code but there are few undefined Macro/functions like MK_FP().

I am trying it on WIN32, VS2012.. i have made changes accordingly.

Is this solution dependent on any library.

Thanks in advance





On Monday, August 1, 1994 1:02:48 PM UTC+5:30, Cyborg wrote:

> In article <msm6.775622996@...> msm6@... (Muhammad Salman Mughal) writes:

> >

> >Hi there,

> >

> > I am desperately looking for a C code that could decode a GIF file

> > in DOS. Anybody out there who knows how to do it? I will really

> > appreciate any help.

> >

>

>

> The following code is based on a LZW decoder originally coded by Steven A.

> Bennett. All I did is write the code for parsing the GIF format, passing

> the approptiate data to the LZW decoder and writing the code for displaying

> the data on the screen. Both 87a and 89a formats are accepted.

>

> Video BIOS must support VESA functions - the code selects a video mode

> whith a resolution just high enough to display the given GIF file. Max

> resolution is 1280x1024, pictures larger than this will be partially

> displayed. Interlaced GIFs are supported. Program was only tested on my

> video card (Cirrus 5428 VESA Local Bus). It was not intended for public

> release but since I've already written it and the guy i desperate...

>

> Compiles with Borland C++ v3.1

>

> ----------------------- chop here --------------------------

>

> /* Various error codes used by decoder

> * and my own routines... It's okay

> * for you to define whatever you want,

> * as long as it's negative... It will be

> * returned intact up the various subroutine

> * levels...

> */

> #define READ_ERROR -1

> #define WRITE_ERROR -2

> #define OPEN_ERROR -3

> #define CREATE_ERROR -4

> #define OUT_OF_MEMORY -5

> #define BAD_CODE_SIZE -6

>

> #define ISIZE 2048 // image line size

> #define BSIZE 256 // buffer size

> #define PSIZE 768 // pallette size

> #define NULL 0L

> #define MAX_CODES 4095

>

> #include <dos.h>

> #include <conio.h>

> #include <stdio.h>

> #include <stdlib.h>

> #include <string.h>

>

> /* Static variables */

> short curr_size; /* The current code size */

> short clear; /* Value for a clear code */

> short ending; /* Value for a ending code */

> short newcodes; /* First available code */

> short top_slot; /* Highest code for current size */

> short slot; /* Last read code */

>

> /* The following static variables are used

> * for seperating out codes

> */

> short navail_bytes = 0; /* # bytes left in block */

> short nbits_left = 0; /* # bits left in current byte */

> unsigned char b1; /* Current byte */

> unsigned char byte_buff[257]; /* Current block */

> unsigned char *pbytes; /* Pointer to next byte in block */

>

> /* The reason we have these separated like this instead of using

> * a structure like the original Wilhite code did, is because this

> * stuff generally produces significantly faster code when compiled...

> * This code is full of similar speedups... (For a good book on writing

> * C for speed or for space optimisation, see Efficient C by Tom Plum,

> * published by Plum-Hall Associates...)

> */

> unsigned char stack[MAX_CODES + 1]; /* Stack for storing pixels */

> unsigned char suffix[MAX_CODES + 1]; /* Suffix table */

> unsigned short prefix[MAX_CODES + 1]; /* Prefix linked list */

>

> long code_mask[13] = {

> 0x0000,

> 0x0001, 0x0003, 0x0007, 0x000F,

> 0x001F, 0x003F, 0x007F, 0x00FF,

> 0x01FF, 0x03FF, 0x07FF, 0x0FFF

> };

>

> // incremented each time an out of range code is read by the decoder

> int bad_code_count;

>

> unsigned char far *buffer=NULL; // file buffer

> unsigned char far *grgb=NULL; // global rgb table

> unsigned char far *lrgb=NULL; // local rgb table

> unsigned char far *pixels=NULL; // line of pixels to be displayed

> unsigned char far *vid=NULL; // ptr to start of graphics window

> unsigned char background=0; // background color index

> unsigned long offset=0; // offset into graphics window

> unsigned long piclen; // total screen size in pixels

> unsigned int realx; // real picture width

> unsigned int realy; // real picture height

> unsigned int xsize=0; // graphic width

> unsigned int ysize=0; // graphic height

> unsigned int win=0; // window number

> unsigned int granularity=0; // granularity of video window

> unsigned int group=0; // picture group (interlaced or not)

> FILE *fp; // file pointer

>

> /* int get_byte()

> * - This function is expected to return the next byte from

> * the GIF file or a negative number defined in ERRS.H

> */

> int get_byte(){

> unsigned char c;

>

> if(fscanf(fp, "%c", &c)==1)

> return((int)c);

> else

> return(READ_ERROR);

> }

>

> /* int out_line(unsigned char pixels[], int linelen)

> * - This function takes a full line of pixels (one byte per pixel) and

> * displays them (or does whatever your program wants with them...). It

> * should return zero, or negative if an error or some other event occurs

> * which would require aborting the decode process... Note that the length

> * passed will almost always be equal to the line length passed to the

> * decoder function, with the sole exception occurring when an ending code

> * occurs in an odd place in the GIF file... In any case, linelen will be

> * equal to the number of pixels passed...

> */

> int out_line(unsigned char *pixels, int linelen){

> unsigned long segment;

>

> segment=offset&(unsigned long)(granularity-1);

>

> // put pixels on screen

> memmove(vid+segment, pixels, linelen);

> memset(vid+segment+linelen, background, xsize-linelen);

> switch (group) {

> case 0:

> offset+=xsize;

> break;

> case 1:

> offset+=xsize*8;

> if(offset>=piclen){

> group++;

> offset=xsize*4;

> }

> break;

> case 2:

> offset+=xsize*8;

> if(offset>=piclen){

> group++;

> offset=xsize*2;

> }

> break;

> case 3:

> offset+=xsize*4;

> if(offset>=piclen){

> group++;

> offset=xsize;

> }

> break;

> case 4:

> offset+=xsize*2;

> break;

> default:

> break;

> }

>

> // if we've run over a window granularity border, move window position

> if((offset>>12)!=win){

> win=offset>>12;

> asm pusha

> asm mov ax, 0x4f05

> asm mov bx, 0x0000

> asm mov dx, win

> asm int 0x10

> asm popa

> }

> return(1);

> }

>

>

> /* This function initializes the decoder for reading a new image.

> */

> static short init_exp(short size)

> {

> curr_size = size + 1;

> top_slot = 1 << curr_size;

> clear = 1 << size;

> ending = clear + 1;

> slot = newcodes = ending + 1;

> navail_bytes = nbits_left = 0;

> return(0);

> }

>

> /* get_next_code()

> * - gets the next code from the GIF file. Returns the code, or else

> * a negative number in case of file errors...

> */

> static short get_next_code()

> {

> short i, x;

> unsigned long ret;

>

> if (nbits_left == 0)

> {

> if (navail_bytes <= 0)

> {

>

> /* Out of bytes in current block, so read next block

> */

> pbytes = byte_buff;

> if ((navail_bytes = get_byte()) < 0)

> return(navail_bytes);

> else if (navail_bytes)

> {

> for (i = 0; i < navail_bytes; ++i)

> {

> if ((x = get_byte()) < 0)

> return(x);

> byte_buff[i] = x;

> }

> }

> }

> b1 = *pbytes++;

> nbits_left = 8;

> --navail_bytes;

> }

>

> ret = b1 >> (8 - nbits_left);

> while (curr_size > nbits_left)

> {

> if (navail_bytes <= 0)

> {

>

> /* Out of bytes in current block, so read next block

> */

> pbytes = byte_buff;

> if ((navail_bytes = get_byte()) < 0)

> return(navail_bytes);

> else if (navail_bytes)

> {

> for (i = 0; i < navail_bytes; ++i)

> {

> if ((x = get_byte()) < 0)

> return(x);

> byte_buff[i] = x;

> }

> }

> }

> b1 = *pbytes++;

> ret |= b1 << nbits_left;

> nbits_left += 8;

> --navail_bytes;

> }

> nbits_left -= curr_size;

> ret &= code_mask[curr_size];

> return((short)(ret));

> }

>

> /* DECODE.C - An LZW decoder for GIF

> *

> * Copyright (C) 1987, by Steven A. Bennett

> *

> * Permission is given by the author to freely redistribute and include

> * this code in any program as long as this credit is given where due.

> *

> * In accordance with the above, I want to credit Steve Wilhite who wrote

> * the code which this is heavily inspired by...

> *

> * GIF and 'Graphics Interchange Format' are trademarks (tm) of

> * Compuserve, Incorporated, an H&R Block Company.

> *

> * Release Notes: This file contains a decoder routine for GIF images

> * which is similar, structurally, to the original routine by Steve Wilhite.

> * It is, however, somewhat noticably faster in most cases.

> *

> * short decode(linewidth)

> * short linewidth; * Pixels per line of image *

> *

> * - This function decodes an LZW image, according to the method used

> * in the GIF spec. Every *linewidth* "characters" (ie. pixels) decoded

> * will generate a call to out_line(), which is a user specific function

> * to display a line of pixels. The function gets it's codes from

> * get_next_code() which is responsible for reading blocks of data and

> * seperating them into the proper size codes. Finally, get_byte() is

> * the global routine to read the next byte from the GIF file.

> *

> * It is generally a good idea to have linewidth correspond to the actual

> * width of a line (as specified in the Image header) to make your own

> * code a bit simpler, but it isn't absolutely necessary.

> *

> * Returns: 0 if successful, else negative. (See ERRS.H)

> *

> */

>

> short decode(short linewidth)

> {

> register unsigned char *sp, *bufptr;

> unsigned char *buf;

> register short code, fc, oc, bufcnt;

> short c, size, ret;

>

> /* Initialize for decoding a new image...

> */

> if ((size = get_byte()) < 0)

> return(size);

> if (size < 2 || 9 < size)

> return(BAD_CODE_SIZE);

> init_exp(size);

>

> /* Initialize in case they forgot to put in a clear code.

> * (This shouldn't happen, but we'll try and decode it anyway...)

> */

> oc = fc = 0;

>

> /* Allocate space for the decode buffer

> */

> if ((buf = (unsigned char *)malloc(linewidth + 1)) == NULL)

> return(OUT_OF_MEMORY);

>

> /* Set up the stack pointer and decode buffer pointer

> */

> sp = stack;

> bufptr = buf;

> bufcnt = linewidth;

>

> /* This is the main loop. For each code we get we pass through the

> * linked list of prefix codes, pushing the corresponding "character" for

> * each code onto the stack. When the list reaches a single "character"

> * we push that on the stack too, and then start unstacking each

> * character for output in the correct order. Special handling is

> * included for the clear code, and the whole thing ends when we get

> * an ending code.

> */

> while ((c = get_next_code()) != ending)

> {

>

> /* If we had a file error, return without completing the decode

> */

> if (c < 0)

> {

> free(buf);

> return(0);

> }

>

> /* If the code is a clear code, reinitialize all necessary items.

> */

> if (c == clear)

> {

> curr_size = size + 1;

> slot = newcodes;

> top_slot = 1 << curr_size;

>

> /* Continue reading codes until we get a non-clear code

> * (Another unlikely, but possible case...)

> */

> while ((c = get_next_code()) == clear)

> ;

>

> /* If we get an ending code immediately after a clear code

> * (Yet another unlikely case), then break out of the loop.

> */

> if (c == ending)

> break;

>

> /* Finally, if the code is beyond the range of already set codes,

> * (This one had better NOT happen... I have no idea what will

> * result from this, but I doubt it will look good...) then set it

> * to color zero.

> */

> if (c >= slot)

> c = 0;

>

> oc = fc = c;

>

> /* And let us not forget to put the char into the buffer... And

> * if, on the off chance, we were exactly one pixel from the end

> * of the line, we have to send the buffer to the out_line()

> * routine...

> */

> *bufptr++ = c;

> if (--bufcnt == 0)

> {

> if ((ret = out_line(buf, linewidth)) < 0)

> {

> free(buf);

> return(ret);

> }

> bufptr = buf;

> bufcnt = linewidth;

> }

> }

> else

> {

>

> /* In this case, it's not a clear code or an ending code, so

> * it must be a code code... So we can now decode the code into

> * a stack of character codes. (Clear as mud, right?)

> */

> code = c;

>

> /* Here we go again with one of those off chances... If, on the

> * off chance, the code we got is beyond the range of those already

> * set up (Another thing which had better NOT happen...) we trick

> * the decoder into thinking it actually got the last code read.

> * (Hmmn... I'm not sure why this works... But it does...)

> */

> if (code >= slot)

> {

> if (code > slot)

> ++bad_code_count;

> code = oc;

> *sp++ = fc;

> }

>

> /* Here we scan back along the linked list of prefixes, pushing

> * helpless characters (ie. suffixes) onto the stack as we do so.

> */

> while (code >= newcodes)

> {

> *sp++ = suffix[code];

> code = prefix[code];

> }

>

> /* Push the last character on the stack, and set up the new

> * prefix and suffix, and if the required slot number is greater

> * than that allowed by the current bit size, increase the bit

> * size. (NOTE - If we are all full, we *don't* save the new

> * suffix and prefix... I'm not certain if this is correct...

> * it might be more proper to overwrite the last code...

> */

> *sp++ = code;

> if (slot < top_slot)

> {

> suffix[slot] = fc = code;

> prefix[slot++] = oc;

> oc = c;

> }

> if (slot >= top_slot)

> if (curr_size < 12)

> {

> top_slot <<= 1;

> ++curr_size;

> }

>

> /* Now that we've pushed the decoded string (in reverse order)

> * onto the stack, lets pop it off and put it into our decode

> * buffer... And when the decode buffer is full, write another

> * line...

> */

> while (sp > stack)

> {

> *bufptr++ = *(--sp);

> if (--bufcnt == 0)

> {

> if ((ret = out_line(buf, linewidth)) < 0)

> {

> free(buf);

> return(ret);

> }

> bufptr = buf;

> bufcnt = linewidth;

> }

> }

> }

> }

> ret = 0;

> if (bufcnt != linewidth)

> ret = out_line(buf, (linewidth - bufcnt));

> free(buf);

> return(ret);

> }

>

>

> // this function is called just before program exits

> void cleanup(void){

> // free any allocated resources

> if(fp!=NULL)

> fclose(fp);

> if(buffer!=NULL)

> free(buffer);

> if(grgb!=NULL)

> free(grgb);

> if(lrgb!=NULL)

> free(lrgb);

> if(pixels!=NULL)

> free(pixels);

> }

>

> void main(int argc, char **argv){

> unsigned int gctsize=0, lctsize=0, mode;

> int i;

>

> // set bad codes encountered to zero

> bad_code_count=0;

>

> // set function to be called on exit

> if(atexit(cleanup))

> exit(0);

>

> // exit if no file given

> if (argc<2){

> printf("Usage: %s gif_file\n", argv[0]);

> exit(0);

> }

>

> // try to open file

> if((fp=fopen(argv[1], "rb"))==NULL){

> printf("Failed to open file.\n");

> exit(0);

> }

>

> // allocate buffers

> buffer=(unsigned char *)malloc(BSIZE);

> pixels=(unsigned char *)malloc(ISIZE);

> grgb =(unsigned char *)malloc(PSIZE);

> lrgb =(unsigned char *)malloc(PSIZE);

> if((grgb==NULL) || (lrgb==NULL) || (pixels==NULL) || (buffer==NULL)){

> printf("Not enough memory.\n");

> exit(0);

> }

>

> fread(buffer, 1, 6, fp);

> // test file for valid GIF signature

> if(memcmp(buffer, "GIF", 3)!=0){

> printf("Not a GIF file.\n");

> exit(0);

> }

> // test file for version number

> if((memcmp(buffer+3, "87a", 3)!=0) && (memcmp(buffer+3, "89a", 3)!=0)){

> printf("Unsuported GIF version. Hit a key to decode anyway.\n");

> getch();

> }

>

> // read logical screen descriptor

> fread(buffer, 1, 7, fp);

>

> // test for global color table presence

> if(*(buffer+4)&0x80){

> // compute global color table size

> gctsize=1<<((*(buffer+4)&0x07) + 1);

> // read global color table into buffer

> fread(grgb, 1, gctsize*3, fp);

> // adjust colors to crappy 6-bit PC-DAC values

> for(i=0; i<gctsize*3; i++)

> *(grgb+i)>>=2;

> }

> // get background color index

> background=*(buffer+5);

>

>

> // scan file for data blocks

> while((i=get_byte())>0) {

> // in end of GIF marker encountered then exit

> if(i==0x3b)

> exit(0);

> // test for extentions

> if(i==0x21){

> if( (i=get_byte()) < 0 )

> exit(0);

> // if graphic color extention present or

> // coment extention present or

> // plain text extention present or

> // application extention present then skip it

> if( (i==0x01) || (i==0xf9) || (i==0xfe) || (i==0xff)){

> while((i=get_byte())!=0){

> if(fread(buffer, 1, i, fp)!=i)

> exit(0);

> }

> }

> }

>

> // test for presence of image descriptor

> if(i==0x2c){

> // get image descriptor

> fread(buffer, 1, 9, fp);

> // interlaced flag is set or cleared accordingly

> if(*(buffer+8)&0x40)

> group=1;

> realx=xsize=*(buffer+4) | (*(buffer+5)<<8);

> realy=ysize=*(buffer+6) | (*(buffer+7)<<8);

> // test for presence of local color table

> if(*(buffer+8)&0x80){

> // compute local color table size

> lctsize=1<<((*(buffer+8)&0x07) + 1);

> // read local color table into buffer

> fread(lrgb, 1, lctsize*3, fp);

> // adjust colors to crappy 6-bit PC-DAC values

> for(i=0; i<gctsize*3; i++)

> *(lrgb+i)>>=2;

> }

>

> // choose a video mode that will just fit the image

> if((xsize<=640) && (ysize<=480)){

> mode=0x101; // VESA 640 x 480 x 256

> xsize=640;

> ysize=480;

> } else if ((xsize<=800) && (ysize<=600)){

> mode=0x103; // VESA 800 x 600 x 256

> xsize=800;

> ysize=600;

> } else if ((xsize<=1024) && (ysize<=768)){

> mode=0x105; // VESA 1024 x 768 x 256

> xsize=1024;

> ysize=768;

> } else {

> mode=0x107; // VESA 1280 x 1024 x 256

> xsize=1280;

> ysize=1024;

> }

>

> piclen=(unsigned long)xsize*(unsigned long)ysize;

> // get video mode info through VESA call

> asm pusha

> asm mov ax, 0x4f01

> asm mov cx, mode

> asm les di, buffer

> asm int 0x10

> asm mov i, ax

> asm popa

>

> if(i!=0x004f){

> printf("VESA video functions not available.\n");

> exit(0);

> }

> // if mode not supported, or not color, or not graphics then exit

> if((*buffer&0x19)!=0x19){

> printf("Required graphics mode is not available.\n");

> exit(0);

> }

>

> // if window does not exist or is not writable exit

> if((*(buffer+2)&0x05)!=0x05) {

> printf("Cannot access video RAM.\n");

> exit(0);

> }

>

> // calculate window granularity

> granularity=(*(buffer+4) | (*(buffer+5)<<8))<<10;

> // calculate pointer to video RAM start

> vid=(unsigned char *)MK_FP((*(buffer+8) | (*(buffer+9)<<8)), 0);

>

> // set VESA video mode

> asm pusha

> asm mov ax, 0x4f02

> asm mov bx, mode

> asm int 0x10

> asm popa

>

> // set color table if present

> if(lctsize){

> // scope of local color table is local so once used it's gone

> lctsize=0;

> asm pusha

> asm mov ax, 0x1012

> asm mov bx, 0x0000

> asm mov cx, 0x0100

> asm les dx, lrgb

> asm int 0x10

> asm popa

> } else if(gctsize){

> // if no local color table then set global color table if present

> asm pusha

> asm mov ax, 0x1012

> asm mov bx, 0x0000

> asm mov cx, 0x0100

> asm les dx, grgb

> asm int 0x10

> asm pop es

> asm popa

> }

>

> // decode and display graphic

> decode(realx);

> // wait for key press

> getch();

>

> // set default text mode

> asm mov ax, 0x0003

> asm int 0x10

> }

> }

>

> // exit to dos

> exit(0);

> }

>

> -------------- chop here -------------------

>

> --

> +-----------------------------+-----------------------------------------------+

> | Alex Ivopol | If you love something set it free. If it |

> | cyborg@... | doesn't come back, hunt it down and kill it. |

> +-----------------------------+-----------------------------------------------+







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1dP9txL

View all the progranning help forums at:

http://ift.tt/1dP9txN