Current time: 23.03.2024, 17:37 Hello There, Guest! (LoginRegister)
Language: english | russian  

Post Reply 
Threaded Mode | Linear Mode
С++, общая тема
Author Message
Efrit Offline
Administrators

Posts: 6183
Post: #196

Столкнулся с забавным фактом. Не знаю, баг ли это или фича - но штука странная.

В общем, если в опциях компилятора gcc включена поддержка c++11, то перестаёт работать инклуд математических констант из <cmath> - например, хорошо всем знакомых M_PI и M_E.
Если отключить поддержку нового стандарта - то всё инклудится хорошо, как и раньше...

Пришлось использовать <qmath.h> (в Qt) - с ним такой проблемы не наблюдается. Вроде бы, это полный аналог <cmath>, или всё же нет?


Welcome to the soldier side,
Where there is no one here but me.
People all grow up to die,
There is no one here but me...
22.04.2012 23:33
Find all posts by this user Quote this message in a reply
gamecreator Offline

Posts: 7107
Post: #197

а почему не math.h?


When all gods have burnt to ashes in eternity of sorrow,
Demons gonna tear your soul because there is no tomorrow.
23.04.2012 00:01
Find all posts by this user Quote this message in a reply
Efrit Offline
Administrators

Posts: 6183
Post: #198

Так это же то же самое, что и <cmath>.


Welcome to the soldier side,
Where there is no one here but me.
People all grow up to die,
There is no one here but me...
23.04.2012 00:05
Find all posts by this user Quote this message in a reply
gamecreator Offline

Posts: 7107
Post: #199

точно? ты проверял? из math.h тоже не подтягивает пи и е? потому что cstring и string.h насколько я знаю - далеко не то же самое.

попробуй открыть cmath и посмотреть, может там надо какой-нибудь идентификатор объявить типа USE_MATH_DEFINES? кажись, еще в 9-й студии нужно было объявлять (не говоря уже о всех последующих)


When all gods have burnt to ashes in eternity of sorrow,
Demons gonna tear your soul because there is no tomorrow.
(This post was last modified: 23.04.2012 01:17 by gamecreator.)
23.04.2012 01:13
Find all posts by this user Quote this message in a reply
Efrit Offline
Administrators

Posts: 6183
Post: #200

gamecreator Wrote:точно? ты проверял?
Да точно, это известный факт. Это же C++, в ней вся стандартная сишная библиотека не имеет расширений. Недаром же ты пишешь просто include <iostream>... Вот, Википедия подтверждает.

gamecreator Wrote:из math.h тоже не подтягивает пи и е?
Тоже, естественно.

gamecreator Wrote:попробуй открыть cmath и посмотреть, может там надо какой-нибудь идентификатор объявить типа USE_MATH_DEFINES?
Легко сказать - открой и посмотри Sm Там же повсюду условная компиляция с огромным числом констант... Да и прекрасно всё работает без каких-либо идентификаторов, если не под c++11 пытаться.

gamecreator Wrote:кажись, еще в 9-й студии нужно было объявлять (не говоря уже о всех последующих)
А причём здесь студия? Я же не под ней работаю...


Welcome to the soldier side,
Where there is no one here but me.
People all grow up to die,
There is no one here but me...
23.04.2012 08:56
Find all posts by this user Quote this message in a reply
gamecreator Offline

Posts: 7107
Post: #201

(23.04.2012 08:56)Efrit Wrote:  Недаром же ты пишешь просто include <iostream>
вот как раз iostream не равно iostream.h. поэтому и пишу
(23.04.2012 08:56)Efrit Wrote:  Легко сказать - открой и посмотри Sm Там же повсюду условная компиляция с огромным числом констант...
поиск люди придумали для таких ситуаций. я же находил в свое время. если совсем невмоготу - скинь файл, найти - дело пары минут.
(23.04.2012 08:56)Efrit Wrote:  А причём здесь студия? Я же не под ней работаю...
так файлы то могут быть и похожи. или по-твоему они их с нуля переписывают для каждого компилятора?


When all gods have burnt to ashes in eternity of sorrow,
Demons gonna tear your soul because there is no tomorrow.
23.04.2012 09:12
Find all posts by this user Quote this message in a reply
Efrit Offline
Administrators

Posts: 6183
Post: #202

Википедия Wrote:Каждый заголовочный файл из стандартной библиотеки языка Си включен в стандартную библиотеку языка C++ под различными именами, созданных путем отсечения расширения .h и добавлением 'c' в начале, например, 'time.h' стал 'ctime'.
Это же, кстати, относится и к <cstring>. А вот <iostream> - да, всё-таки другой.

gamecreator Wrote:если совсем невмоготу - скинь файл, найти - дело пары минут.
Ну вот, погляди 118


Welcome to the soldier side,
Where there is no one here but me.
People all grow up to die,
There is no one here but me...
23.04.2012 09:25
Find all posts by this user Quote this message in a reply
gamecreator Offline

Posts: 7107
Post: #203

cmath Wrote:#include <math.h>
они в math.h


When all gods have burnt to ashes in eternity of sorrow,
Demons gonna tear your soul because there is no tomorrow.
23.04.2012 09:46
Find all posts by this user Quote this message in a reply
Efrit Offline
Administrators

Posts: 6183
Post: #204

И что с этого? Даже если компиляция действительно идёт по указанной тобой ветке, то константы оттуда всё равно не инклудятся...

Ты лучше скажи мне, по какой ветке идёт компиляция при включении c++11 Ab


Welcome to the soldier side,
Where there is no one here but me.
People all grow up to die,
There is no one here but me...
23.04.2012 09:56
Find all posts by this user Quote this message in a reply
gamecreator Offline

Posts: 7107
Post: #205

math.h включается всегда в cmath. так что:
Code:
#if defined(_USE_MATH_DEFINES) && !defined(_MATH_DEFINES_DEFINED)
#define _MATH_DEFINES_DEFINED

/* Define _USE_MATH_DEFINES before including math.h to expose these macro
* definitions for common math constants.  These are placed under an #ifdef
* since these commonly-defined names are not part of the C/C++ standards.
*/

/* Definitions of useful mathematical constants
* M_E        - e
* M_LOG2E    - log2(e)
* M_LOG10E   - log10(e)
* M_LN2      - ln(2)
* M_LN10     - ln(10)
* M_PI       - pi
* M_PI_2     - pi/2
* M_PI_4     - pi/4
* M_1_PI     - 1/pi
* M_2_PI     - 2/pi
* M_2_SQRTPI - 2/sqrt(pi)
* M_SQRT2    - sqrt(2)
* M_SQRT1_2  - 1/sqrt(2)
*/

#define M_E        2.71828182845904523536
#define M_LOG2E    1.44269504088896340736
#define M_LOG10E   0.434294481903251827651
#define M_LN2      0.693147180559945309417
#define M_LN10     2.30258509299404568402
#define M_PI       3.14159265358979323846
#define M_PI_2     1.57079632679489661923
#define M_PI_4     0.785398163397448309616
#define M_1_PI     0.318309886183790671538
#define M_2_PI     0.636619772367581343076
#define M_2_SQRTPI 1.12837916709551257390
#define M_SQRT2    1.41421356237309504880
#define M_SQRT1_2  0.707106781186547524401

#endif  /* _USE_MATH_DEFINES */


более того,
math.h Wrote:These are placed under an #ifdef since these commonly-defined names are not part of the C/C++ standards.
что означает, что в gcc их быть не может, основная фишка gcc - стандарты же


When all gods have burnt to ashes in eternity of sorrow,
Demons gonna tear your soul because there is no tomorrow.
(This post was last modified: 23.04.2012 10:04 by gamecreator.)
23.04.2012 10:01
Find all posts by this user Quote this message in a reply
Efrit Offline
Administrators

Posts: 6183
Post: #206

Да причём здесь вообще всё это? Ну да, объявлены они в math.h, и что?
Про проблему с использованием c++11 здесь ни слова не сказано...

Есичо, я пробовал дефайнить _USE_MATH_DEFINES перед инклудом <cmath> - не помогало.


Welcome to the soldier side,
Where there is no one here but me.
People all grow up to die,
There is no one here but me...
23.04.2012 10:08
Find all posts by this user Quote this message in a reply
gamecreator Offline

Posts: 7107
Post: #207

значит для с++11 есть другой набор заголовков или его особенности влияют на компиляцию этих.


When all gods have burnt to ashes in eternity of sorrow,
Demons gonna tear your soul because there is no tomorrow.
23.04.2012 10:16
Find all posts by this user Quote this message in a reply
Efrit Offline
Administrators

Posts: 6183
Post: #208

Вот и я про что. Либо что-то дополнительно надо дефайнить, либо действительно баг.
По крайней мере, в Qt помогает инклуд <qmath.h> - а вот как быть в "чистом" gcc, я даже не знаю...


Welcome to the soldier side,
Where there is no one here but me.
People all grow up to die,
There is no one here but me...
23.04.2012 10:18
Find all posts by this user Quote this message in a reply
gamecreator Offline

Posts: 7107
Post: #209

самому писать нужные функции Sm


When all gods have burnt to ashes in eternity of sorrow,
Demons gonna tear your soul because there is no tomorrow.
23.04.2012 10:32
Find all posts by this user Quote this message in a reply
Efrit Offline
Administrators

Posts: 6183
Post: #210

gamecreator Wrote:самому писать нужные функции Sm

Ага, как же Rolleyes

Code:
#ifdef WAR_TIME
   #undef M_PI
   #define M_PI  4  // в военное время число PI может достигать четырёх
#endif  // WAR_TIME


Welcome to the soldier side,
Where there is no one here but me.
People all grow up to die,
There is no one here but me...
23.04.2012 10:49
Find all posts by this user Quote this message in a reply
« Next Oldest | Next Newest »
Post Reply 


Forum Jump:

Powered by MyBB Copyright © 2002-2024 MyBB Group