Sample in documentation

Started by Igor Korotalmost 9 years ago5 messagesgeneral
Jump to latest
#1Igor Korot
ikorot01@gmail.com

Hi, ALL,
I tried to implement the code found in
https://www.postgresql.org/docs/current/static/libpq-example.html.

On Windows with MSVC 2010 and Liniux with gcc-5.4 it compiled fine.

However on OSX 10.8 with:

[code]
Igors-MacBook-Air:dbhandler igorkorot$ gcc --version
Configured with:
--prefix=/Applications/Xcode.app/Contents/Developer/usr
--with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin12.5.0
Thread model: posix
[/code]

I am getting an error:

[quote]
Non-constant-expression cannot be narrowed from type 'size_t' (aka
'unsigned long') to 'int' in initializer list
[/quote]

on the line that tries to create a length[2] array.

Now I should probably change it to "size_t length{2}" instead of "int
length[2]", but
I feel that this should be changed in the documentation.

That is unless I'm missing something and this official sample is correct.

Thank you.

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Igor Korot (#1)
Re: Sample in documentation

Igor Korot <ikorot01@gmail.com> writes:

I tried to implement the code found in
https://www.postgresql.org/docs/current/static/libpq-example.html.
...
I am getting an error:
[quote]
Non-constant-expression cannot be narrowed from type 'size_t' (aka
'unsigned long') to 'int' in initializer list
[/quote]
on the line that tries to create a length[2] array.

Now I should probably change it to "size_t length{2}" instead of "int
length[2]", but
I feel that this should be changed in the documentation.

I do not see any arrays named "length", nor even any arrays of size 2,
on that page, so I'm pretty confused what you're talking about. Please
be more specific.

regards, tom lane

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#3Igor Korot
ikorot01@gmail.com
In reply to: Tom Lane (#2)
Re: Sample in documentation

Hi, Tom,

On Sat, May 6, 2017 at 8:22 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Igor Korot <ikorot01@gmail.com> writes:

I tried to implement the code found in
https://www.postgresql.org/docs/current/static/libpq-example.html.
...
I am getting an error:
[quote]
Non-constant-expression cannot be narrowed from type 'size_t' (aka
'unsigned long') to 'int' in initializer list
[/quote]
on the line that tries to create a length[2] array.

Now I should probably change it to "size_t length{2}" instead of "int
length[2]", but
I feel that this should be changed in the documentation.

I do not see any arrays named "length", nor even any arrays of size 2,
on that page, so I'm pretty confused what you're talking about. Please
be more specific.

I based my code on this:
http://stackoverflow.com/questions/26911855/correct-way-to-bind-numeric-values-to-prepared-sql.
Sorry about that.

Nevertheless, while it did compile by MSVC and gcc, it looks like
Xcode fails with compiling that code.
The code is located inside the C++ dynamic library project. It is
compiled with C++11 mode.
I am trying to compile it on OSX 10.8 with minimum required OSX set to be 10.8.

Nevertheless, it should compile fine.

Now when I tried to switch to size_t, it fails further down on the
call to PQexecPrepared().

So, is there any solution to this which can be used cross-platform?

Thank you.

regards, tom lane

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Igor Korot (#3)
Re: Sample in documentation

Igor Korot <ikorot01@gmail.com> writes:

On Sat, May 6, 2017 at 8:22 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

I do not see any arrays named "length", nor even any arrays of size 2,
on that page, so I'm pretty confused what you're talking about. Please
be more specific.

I based my code on this:
http://stackoverflow.com/questions/26911855/correct-way-to-bind-numeric-values-to-prepared-sql.
Sorry about that.

Ah. Well, we can't be responsible for random bits of code posted on
stackoverflow.

Nevertheless, while it did compile by MSVC and gcc, it looks like
Xcode fails with compiling that code.

Seems to me clang is being overly picky, but whatever.

So, is there any solution to this which can be used cross-platform?

Don't use an initializer, assign the values one at a time.

Back in the day we used to avoid use of initializers for local variables
because they weren't too portable. It's depressing to see clang
introducing new reasons for them not to be portable.

regards, tom lane

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#5Igor Korot
ikorot01@gmail.com
In reply to: Tom Lane (#4)
Re: Sample in documentation

Tom et al,

On Sun, May 7, 2017 at 1:09 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Igor Korot <ikorot01@gmail.com> writes:

On Sat, May 6, 2017 at 8:22 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

I do not see any arrays named "length", nor even any arrays of size 2,
on that page, so I'm pretty confused what you're talking about. Please
be more specific.

I based my code on this:
http://stackoverflow.com/questions/26911855/correct-way-to-bind-numeric-values-to-prepared-sql.
Sorry about that.

Ah. Well, we can't be responsible for random bits of code posted on
stackoverflow.

Nevertheless, while it did compile by MSVC and gcc, it looks like
Xcode fails with compiling that code.

Seems to me clang is being overly picky, but whatever.

So, is there any solution to this which can be used cross-platform?

Don't use an initializer, assign the values one at a time.

Yes, that's what I ended up doing.

Back in the day we used to avoid use of initializers for local variables
because they weren't too portable. It's depressing to see clang
introducing new reasons for them not to be portable.

OK.
It would be nice to see what Borland would do in this case. ;-)

BTW, what do you guys use to build binaries for OSX? clang? gcc?

Thank you.

regards, tom lane

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general