(part 38) Han from China answers your C questions | Bytes (2024)

Borked Pseudo Mailed

Pointer to pointer

James Kuyper said:

> printf("*a=%p *p=%p %c %s\n", *a, *p, **p, *p);

The "%p" format specifier expects a void* argument. This is one of the
few places where a cast is routinely needed and perfectly correct:

printf("*a=%p *p=%p %c %s\n", (void*)*a, (void*)*p, **p, *p);
printf("*a=%p *p=%p %c %s\n", *a, *p, **p, *p);

Ben Bacarisse said:

> printf("*a=%p *p=%p %c %s\n", *a, *p, **p, *p);
Technical matter: %p expects arguments of type void * and the
conversion is not done automatically so you need to write:

printf("*a=%p *p=%p %c %s\n", (void *)*a, (void *)*p, **p, *p);

I'm not sure James and Ben have this right, but I'd say it's more
probable I'm wrong here. Still, we'll see. CLC psychology dictates
that if I'm wrong, a dozen people with a grudge will be quick to
correct me.

6.2.5 (27) says the following:

"A pointer to void shall have the same representation and alignment
requirements as a pointer to a character type."

And then a footnote for that says:

"The same representation and alignment requirements are meant to
imply interchangeabil ity as arguments to functions ..."

The OP is passing a (char *) to %p. Therefore, he doesn't need to
cast the printf() arguments to (void *).

This is the Unix execl() case in reverse. The function execl(),
for those terminally in ANSI/ISO C land, uses a null character
pointer - i.e., (char *)0 or (char *)NULL - to indicate the end
of its variable-length argument list.

execl("/path/file", "arg", "arg", "arg", NULL);

works if NULL is defined as ((void *) 0), whereas it's not
guaranteed to work if NULL is defined as 0.

Yours,
Han from China

Nov 21 '08 #1

Subscribe Reply

3 (part 38) Han from China answers your C questions | Bytes (1) 1223 (part 38) Han from China answers your C questions | Bytes (2)

Richard Tobin

In article <92************ *************** ***@pseudo.bork ed.net>,
Borked Pseudo Mailed <no****@pseudo. borked.netwrote :

>> printf("*a=%p *p=%p %c %s\n", *a, *p, **p, *p);
>I'm not sure James and Ben have this right, but I'd say it's more
probable I'm wrong here. Still, we'll see. CLC psychology dictates
that if I'm wrong, a dozen people with a grudge will be quick to
correct me.

Okey dokey.

"A pointer to void shall have the same representation and alignment
requirements as a pointer to a character type."

The supposed problem here is that even though they have the same
representation, they may be passed to variadic functions in a
different way. One can imagine this really happening for, say,
ints and doubles, but that it should happen for char * and void *
is implausible.

>And then a footnote for that says:

"The same representation and alignment requirements are meant to
imply interchangeabil ity as arguments to functions ..."

Footnotes are not normative, but this one strongly suggests that the
committee meant it to work.

-- Richard
--
Please remember to mention me / in tapes you leave behind.

Nov 21 '08 #2

Ben Bacarisse

Borked Pseudo Mailed <no****@pseudo. borked.netwrite s:

Pointer to pointer

James Kuyper said:

>> printf("*a=%p *p=%p %c %s\n", *a, *p, **p, *p);

The "%p" format specifier expects a void* argument. This is one of the
few places where a cast is routinely needed and perfectly correct:

printf("*a=% p *p=%p %c %s\n", (void*)*a, (void*)*p, **p, *p);
printf("*a=%p *p=%p %c %s\n", *a, *p, **p, *p);


Ben Bacarisse said:
>> printf("*a=%p *p=%p %c %s\n", *a, *p, **p, *p);
Technical matter: %p expects arguments of type void * and the
conversion is not done automatically so you need to write:

printf("*a=%p *p=%p %c %s\n", (void *)*a, (void *)*p, **p, *p);


I'm not sure James and Ben have this right, but I'd say it's more
probable I'm wrong here.

In the end, my view is that there is no way to escape the effect of
the "shall be a pointer to void" in the description of %p. See
section 4 (Conformance) paragraph 2 -- violating a shall (that is not
a constraint) is undefined behaviour.

Still, we'll see. CLC psychology dictates
that if I'm wrong, a dozen people with a grudge will be quick to
correct me.

6.2.5 (27) says the following:

"A pointer to void shall have the same representation and alignment
requirements as a pointer to a character type."

And then a footnote for that says:

"The same representation and alignment requirements are meant to
imply interchangeabil ity as arguments to functions ..."

The OP is passing a (char *) to %p. Therefore, he doesn't need to
cast the printf() arguments to (void *).

Despite the same representation and alignment, printf (and friends)
may do something non-C-like and specifically permitted (by, say, the
hardware) only for void *s since the standard assures the
implementation that the argument will be a void * and nothing else.

I find it hard to image that it will fail (for a char *) but I also
find it much simpler to cast to void * as specified by the
specification of printf. If I were forced into an alternate, more
expensive, algorithm by a corner case in the standard I might be
tempted to document the choice and wing it, but that is not the case
here.

--
Ben.

Nov 21 '08 #3

jameskuyper

Borked Pseudo Mailed wrote:

Pointer to pointer

James Kuyper said:

printf("*a=%p *p=%p %c %s\n", *a, *p, **p, *p);
The "%p" format specifier expects a void* argument. This is one of the
few places where a cast is routinely needed and perfectly correct:

printf("*a=%p *p=%p %c %s\n", (void*)*a, (void*)*p, **p, *p);
printf("*a=%p *p=%p %c %s\n", *a, *p, **p, *p);


Ben Bacarisse said:
printf("*a=%p *p=%p %c %s\n", *a, *p, **p, *p);
Technical matter: %p expects arguments of type void * and the
conversion is not done automatically so you need to write:

printf("*a=%p *p=%p %c %s\n", (void *)*a, (void *)*p, **p, *p);


I'm not sure James and Ben have this right, but I'd say it's more
probable I'm wrong here. Still, we'll see. CLC psychology dictates
that if I'm wrong, a dozen people with a grudge will be quick to
correct me.

6.2.5 (27) says the following:

"A pointer to void shall have the same representation and alignment
requirements as a pointer to a character type."

And then a footnote for that says:

"The same representation and alignment requirements are meant to
imply interchangeabil ity as arguments to functions ..."

The tricky point is that while "it is meant to imply
interchangeabil ty", it doesn't actually imply it. It's quite feasible
(easy, even) to invent a function calling convention where having the
same representation and alignment is not sufficient to ensure
interchangeabil ity. To take the most direct approach, consider a
function calling convention where each argument is explicitly tagged
according to type. Less directly, consider an API that passes void*
pointers through a different method than char* pointers.

The key point is that while the footnote expresses the intent, the
actual words of the standard fail to mandate that the intent be
achieved. I'd be much happier if the standard said explicitly and
directly, in the normative text (footnotes are not normative), that
these type were interchangeable for the specified purposes.

Nov 21 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1 1959

(part 11) Han from China answers your C questions

by: Nomen Nescio |last post by:

A new learner's question Flash Gordon wrote: To the OP, please be aware that Flash Gordon has a history of either deliberately misleading and "miss-informing" posters to this newsgroup or providing facile answers with which to amuse himself. In this case, both. Facile because Flash Gordon did not tell you substantially anything more than your compiler had told you. Misleading

C / C++

1479

(part 12) Han from China answers your C questions

by: Nomen Nescio |last post by:

what is the type for this call? Neo said: Neo, buddy, I've decided to give you a little summary for reference so that you don't have to sift through excess verbiage, cryptic meanderings, and irrelevant matters of naming to make sense of this thing. Please forgive any typos on my part.

C / C++

1299

(part 14) Han from China answers your C questions

by: Nomen Nescio |last post by:

No format string passed to variable argument list function Adam said: Then Adam laters says: Then Adam later says:

C / C++

2 1504

Re: (part 15) Han from China answers your C questions

by: Chris Dollin |last post by:

Joachim Schmitz wrote: I think that remark is an ill-considered and unhelpful generalisation. -- "We dance, and the worlds melt away." - Curved Air, /Metamorphosis/ Hewlett-Packard Limited registered no: registered office: Cain Road, Bracknell, Berks RG12 1HN 690597 England

C / C++

2 1539

(part 23) Han from China answers your C questions

by: Borked Pseudo Mailed |last post by:

float and integers c.lang.myself@gmail.com said I will be making assumptions here about your system that will infuriate the pedants, but I don't care. Given your X-HTTP-UserAgent string, it is highly probable that these assumptions are valid. Whether you have included stdio.h or not, the float argument to printf() is promoted to a double, since even with a prototype

C / C++

1 1485

(part 22) Han from China answers your C questions

by: George Orwell |last post by:

its urgent.pls help me. mona said: mona said: Hey again, mona. Please check the thread "(part 21) Han from China answers your C questions", in which I gave you a program with

C / C++

1371

(part 27) Han from China answers your C questions

by: George Orwell |last post by:

fread breaks file descriptors opened in "w" mode. ... Yes, once you break out of ANSI/ISO C, all things are possible. You have posted an on-topic question to comp.lang.c. See version 2.0 of my topicality FAQ if anyone should tell you otherwise. Search: "Han from China's comp.lang.c topicality FAQ (version 2.0)"

C / C++

16 1812

(part 30) Han from China answers your C questions

by: Borked Pseudo Mailed |last post by:

Error handling in C Nick Keighley said: ... ... To the OP, please be aware that Nick Keighley is a known troll and is deliberately providing you with unsound advice. You asked for error handling, not error generation (or much worse).

C / C++

2 2205

(part 29) Han from China answers your C questions

by: Nomen Nescio |last post by:

What is this? Eric said: That looks like either someone's poor coding or someone's poor pasting for an implementation of offsetof() from stddef.h. The (char *) leads me to think that there's plenty of missing context, so post the surrounding code, and we'll be happy to jerk ourselves off analyzing the code for you and telling you why it won't work on the control system for your Tomahawk missile.

C / C++

1 1597

(part 32) Han from China answers your C questions

by: George Orwell |last post by:

File Seeking / Overwriting bytes Martien Verbruggen said: And this is, of course, also not right. fseek() does support SEEK_END on text streams. If you want to know why, please start a thread on comp.lang.c. Also, you could read "(part 18) Han from China answers your C questions".

C / C++

9420

Changing the language in Windows 10

by: Hystou |last post by:

Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...

Windows Server

10035

Maximizing Business Potential: The Nexus of Website Design and Digital Marketing

by: jinu1996 |last post by:

In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...

Online Marketing

1 9982

The easy way to turn off automatic updates for Windows 10/11

by: Hystou |last post by:

Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...

Windows Server

9851

Discussion: How does Zigbee compare with other wireless protocols in smart home applications?

by: tracyyun |last post by:

Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...

General

8862

AI Job Threat for Devs

by: agi2029 |last post by:

Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...

Career Advice

1 7398

Access Europe - Using VBA to create a class based on a table - Wed 1 May

by: isladogs |last post by:

The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...

Microsoft Access / VBA

6662

Couldn’t get equations in html when convert word .docx file to html file in C#.

by: conductexam |last post by:

I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...

C# / C Sharp

5293

Trying to create a lan-to-lan vpn between two differents networks

by: TSSRALBI |last post by:

Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...

Networking - Hardware / Configuration

2 3554

How to add payments to a PHP MySQL app.

by: muto222 |last post by:

How can i add a mobile payment intergratation into php mysql website.

PHP

(part 38) Han from China answers your C questions | Bytes (2024)

FAQs

What were the reasons for the fall of Han China? ›

Over time they developed three main theories: 1) bad rulers; 2) the influence of empresses and court eunuchs over child emperors too young to rule by themselves; and 3) the Yellow Turban Revolt.

Who defeated the Han Dynasty? ›

The Han dynasty formally ended in 220 when Cao Cao's son and heir, Cao Pi, pressured Emperor Xian into abdicating in his favour.

How did the Han Dynasty lose the mandate of heaven? ›

Their success was based on the opinion of the gods. If the gods became unhappy with an emperor's rule, it was believed that signs would be sent to the Chinese people, usually in the form of natural disasters. In this event, the emperor lost the Heavenly Mandate, and was usually overthrown.

Why was the Han Dynasty so good? ›

The Han dynasty (206 BCE–220 CE) is known its long reign and its achievements, which included the development of the civil service and government structure; scientific advancements such as the invention of paper, use of water clocks and sundials to measure time, and development of a seismograph; the Yuefu, which ...

What happened to China after the collapse of the Han dynasty? ›

The Han Dynasty ultimately collapsed in 220 CE, and China splintered into three warlord kingdoms in what is known as the Three Kingdoms period.

Why do Chinese call themselves Han? ›

The Chinese people were called the “Xia People” or the “Qin People” by their neighboring ethnic minorities before the Han Dynasty (206 B.C.-220 A.D.) and were changed addressee to the “Han People” since the Han Dynasty's prosperity; correspondingly the Chinese nation was called the “Han Nationality”.

What is the old name of China? ›

Before the Qing Dynasty (1644-1911), the Huaxia nationality named their motherland Zhongguo, and after that, it developed into a nation of various nationalities, and was then called Zhonghua Nation (known as Chinese Nation). ZhongdenotesChina and Hua is the Huaxia nationality for short.

What is the bloodiest time in Chinese history? ›

The Three Kingdoms period including the collapse of the Han is one of the bloodiest in Chinese history.

Do Chinese believe in heaven? ›

According to Chinese popular religion, there are three domains in the cosmos — Heaven, Earth, and the Underworld — and each domain is populated by a host of important gods and goddesses. The Heavenly Domain is ruled by the Jade Emperor, who presides over a court of important deities who are worshipped throughout China.

Who was known as the son of heaven? ›

Chinese rulers were traditionally referred to as Son of Heaven (tianzi), and their authority was believed to emanate from tian. Beginning in the Zhou dynasty, sovereignty was explained by the concept of the mandate of heaven (tianming).

What dynasty built the Great Wall of China? ›

Qin Dynasty Construction

Though the beginning of the Great Wall of China can be traced to the fifth century B.C., many of the fortifications included in the wall date from hundreds of years earlier, when China was divided into a number of individual kingdoms during the so-called Warring States Period.

What language did they speak in the Han dynasty? ›

The language being used in Han dynasty is a variety of Old Chinese, which can be used generally for all varieties of Chinese spoken before Southern and Northern Dynasties (5th century).

Why was the Han dynasty bad? ›

Chinese historians have spent more than a thousand years trying to understand why the Han Dynasty collapsed. Over time they developed three main theories: 1) bad rulers; 2) the influence of empresses and court eunuchs over child emperors too young to rule by themselves; and 3) the Yellow Turban Revolt.

What is the meaning of the word Han? ›

ˈhän. 1. : a Chinese dynasty dated 206b.c.–a.d.220 and marked by centralized control through an appointive bureaucracy, a revival of learning, and the penetration of Buddhism. 2. : the Chinese peoples especially as distinguished from non-Chinese (such as Mongolian) elements in the population.

What caused the fall of the Han Dynasty quizlet? ›

The fall of the Han dynasty was due to weak and corrupt leaders and government officials. This resulted in uprisings of the people until they destroyed the Han capital, Luoyang, in 190 AD.

What factors led to the fall of Han China but not of Rome? ›

In contrast, the Han Dynasty fell due to weak tax collectors, too many people and too little land, plus many revolts. Western Rome fell because of unemployment, not enough people to do necessary jobs, and the idea that the people could create their own government and take over the existing government.

What caused the fall of ancient China? ›

In brief,the key reason of the periodic collapse and reconstruction of ancient Chinese civilization is the population pressure in a relatively limited land resources and unfair distribution and possession of social wealth.

What was a major reason for the decline of both the Han Dynasty in China and the Western Roman Empire? ›

Both Rome and the Han dynasty suffered financial loss as elites began to pocket taxes for their own use. Then the empires lost even more tax revenues due to a loss of population because fewer people meant less taxes could be collected.

Top Articles
Latest Posts
Article information

Author: Rubie Ullrich

Last Updated:

Views: 5966

Rating: 4.1 / 5 (72 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Rubie Ullrich

Birthday: 1998-02-02

Address: 743 Stoltenberg Center, Genovevaville, NJ 59925-3119

Phone: +2202978377583

Job: Administration Engineer

Hobby: Surfing, Sailing, Listening to music, Web surfing, Kitesurfing, Geocaching, Backpacking

Introduction: My name is Rubie Ullrich, I am a enthusiastic, perfect, tender, vivacious, talented, famous, delightful person who loves writing and wants to share my knowledge and understanding with you.